PoshRSJob icon indicating copy to clipboard operation
PoshRSJob copied to clipboard

Added Current Host to Threads

Open robrtitus opened this issue 7 years ago • 2 comments

This allows passing open connections through to the threads. For example: without this additional code running Get-AzureRMVM would require running Login-AzureRMAccount on each thread. With the addition of this code you only need to run Login-AzureRMAccount outside the scope of the Start-RSJob cmdlet one time and not in each thread.

Changes proposed in this pull request:

  • Adding $Host to creation of RunspacePool

How to test this code:

  • Create a connection to a service like Microsoft Azure or Exchange Online in host console/ISE
  • Run a command derived from that connection such as Get-AzureRMVM or Get-Mailbox
  • Instead of an error requiring a login the connection will pass through to the threads

Has been tested on (remove any that don't apply):

  • Powershell 5.1
  • Windows 10

robrtitus avatar Jul 26 '17 19:07 robrtitus

My only concern with this is that by add the current host to the runspacepool creation, all of the streams (Verbose, Debug, etc...) will leak to the current console instead of staying hidden in their runspace. I'd be open to adding a parameter such as -UseCurrentPSHost or something similar and then adding this as a feature.

proxb avatar Jul 31 '17 18:07 proxb

@robrtitus

I'm not an Azure expert, I just checked the doc of Get-AzureRMVM, it seems that it can go with the param -DefaultProfile which might contain Azure crendentials. https://docs.microsoft.com/en-us/powershell/module/azurerm.compute/get-azurermvm?view=azurermps-5.4.0#optional-parameters

If so, you can connect to Azure before PoshRSJob, and passe the connection profile by Start-RSJob -VariablesToImport $azureProfile :

I'm not sure it works, it's just an idea.

copdips avatar Mar 06 '18 21:03 copdips