How to Fix Disconnect-MgGraph closes other PowerShell sessions
Last reviewed
Error message
Calling Disconnect-MgGraph in one PowerShell window appears to also disconnect other windows.
Use separate user accounts or app-only credentials when you need truly isolated sessions.
What this error means
Microsoft Graph PowerShell shares its token cache process-wide on the same user, so disconnecting in one process can affect others started by the same user.
Why this happens
Token cache is per-user-account, not per-PowerShell-window. This is by design but surprises people running parallel scripts.
Quick fix (for end users)
- Avoid calling Disconnect-MgGraph in scripts that run in parallel with other Graph work.
- Run scripts that require isolation under different user identities.
Admin / engineer fix
Use app-only authentication with a unique client ID per script for true isolation.
commandConnect-MgGraph -ClientId <id> -CertificateThumbprint <thumb> -TenantId <tid>Or use ContextScope to limit the token cache lifetime (newer SDK versions).
commandConnect-MgGraph -ContextScope Process
Step-by-step fix
Decide whether you really need to disconnect — just letting the session expire is often fine.
Use ContextScope Process if your SDK supports it.
Affected products
Microsoft.Graph PowerShell SDK
Common variations of this error
People also see these phrasings of the same problem:
Microsoft Graph token cache shared
Still broken? Try these
- Different scripts should authenticate as different identities to avoid cache collisions.
- Use Microsoft.Graph PowerShell SDK 2.x or later — earlier versions have more cache surprises.
Related errors
Related searches
- microsoft graph powershell context scope
- disconnect-mggraph isolated
Frequently asked questions
What does "Disconnect-MgGraph closes other PowerShell sessions" mean?
Microsoft Graph PowerShell shares its token cache process-wide on the same user, so disconnecting in one process can affect others started by the same user.
What causes "Disconnect-MgGraph closes other PowerShell sessions"?
Token cache is per-user-account, not per-PowerShell-window. This is by design but surprises people running parallel scripts.
How do I fix "Disconnect-MgGraph closes other PowerShell sessions"?
1. Decide whether you really need to disconnect — just letting the session expire is often fine. 2. Use ContextScope Process if your SDK supports it. Always test changes in a non-production environment first.
Browse more errors in Microsoft Graph PowerShell: Fix Microsoft Graph PowerShell errors. Insufficient privileges, invalid object ID, missing cmdlets, token problems, and more. Or paste your own error into the error decoder tool to find a match. You can also go back to the homepage to browse common errors by topic.