Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Current Host to Threads #158

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

robrtitus
Copy link

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

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.
@proxb
Copy link
Owner

proxb commented Jul 31, 2017

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.

@copdips
Copy link
Contributor

copdips commented Mar 6, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants