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

Support different contexts per runspace/thread #2543

Open
kwill-MSFT opened this issue Jan 25, 2024 · 0 comments
Open

Support different contexts per runspace/thread #2543

kwill-MSFT opened this issue Jan 25, 2024 · 0 comments

Comments

@kwill-MSFT
Copy link

We have a service which manages cost and security governance across several thousand tenants. This service runs in Azure Functions, which scales out by creating additional Powershell runspaces. The challenge is that the msgraph cmdlets only have a single per-process context which changes when calling Connect-MgGraph.

This causes the following behavior:

  1. Runspace 1 calls Connect-MgGraph -TenantId <Tenant 1> and starts running other graph commands.
  2. Runspace 2 starts and calls onnect-MgGraph -TenantId <Tenant 2>.
  3. Runspace 1 incorrectly executes its commands against Tenant 2.

Our service also manages Azure subscriptions using the Az cmdlets. Az cmdlets solves the multiple runspace issue by providing the -DefaultProfile parameter on all commands. This allows each runspace to execute independently against different tenants and subscriptions. The pattern looks like:

$ctx = Connect-AzAccount -Tenant $TenantId -Subscription $SubId
Get-AzVM -DefaultProfile $ctx

Ask:
Provide a common -DefaultProfile type of parameter for all msgraph cmdlets which allows for a saved context to be utilized.

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

No branches or pull requests

2 participants