microsoftgraph / microsoftgraph/msgraph-sdk-powershell

Support different contexts per runspace/thread

Open
#2,543 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Environment: Azure Functions Request: Feature
Dominant language
C#
Stars
898
Forks
230
Avg merge
2d 5h
Merged PRs (30d)
31

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Connect-MgGraph and how the Microsoft Graph cmdlets store and retrieve their process-wide context; the issue does not name specific files or tests. Define how a shared DefaultProfile-type context would be created and passed so separate runspaces can target different tenants independently, then verify the pattern across the cmdlets.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, powershell
Domain
api, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.