How to get details about the current Microsoft Graph PowerShell context in Microsoft Entra ID

Getting details about the current Microsoft Graph PowerShell context is essential for understanding how sessions interact with resources, permissions, and authentication tokens. For IT admins, this can become complex when multiple tenants or identities are in play, or when scripts run across different environments. The upside is there are reliable methods to quickly review, verify, and manage the current Microsoft Graph PowerShell context effectively.

  • PowerShell
  • ADManager Plus
 

How to get details about the current Microsoft Graph PowerShell context using Windows PowerShell

  • Connect to Microsoft Graph PowerShell.
    Connect-MgGraph -Scopes "User.Read"
  • Get the current context details.
    Get-MgContext

How to get details about the current Microsoft Graph PowerShell context using Microsoft Graph PowerShell

The syntax is as follows:

Get-MgContext

Example

Retrieve details of the current Microsoft Graph context, including account, tenant, environment, and granted scopes.

Example query:

Connect-MgGraph -Scopes "User.Read"
Get-MgContext

Example output:

ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
TenantId: 72f988bf-86f1-41af-91ab-2d7cd011db47
Account: john@testdomain.com
Scopes: {User.Read}
AuthType: Delegated
CertificateThumbprint:
AppName: Microsoft Graph PowerShell
ContextType: MicrosoftGraphPowerShell
Environment: Global

This output shows that the user with the ID e9b1f3a1-1234-4d56-9abc-0def12345678, displayed as John, has been assigned the Global Administrator role. The RoleDefinitionId links this assignment to the Global Administrator role definition in the directory. The PrincipalType confirms that the assignment is for a user (not a group or service principal). Finally, the DirectoryScopeId is set to /, which means this role applies to the entire tenant, not just a specific resource or scope.

Highlights of using ADManager Plus for managing Microsoft 365

ADManager Plus helps admins stay on top of Microsoft 365 management with a simple, centralized console.

User, group, and license management

Create, modify, and manage users, groups, and licenses at scale. Perform bulk updates, adjust memberships, assign or revoke licenses, and keep everyday administrative tasks organized.

Comprehensive reporting

Access more than 200 prebuilt reports, including sign-in activity and account status, to monitor user behavior and maintain visibility across your tenant.

Life cycle management

Automate user provisioning and deprovisioning with role-based group memberships, license assignments, and account setups. Ensure employees have access from day one and remove access immediately when they leave.

Automation

Streamline repetitive tasks such as bulk user changes, license assignments, and group updates. Save time and reduce manual errors with scheduled and event-driven automation.

Delegation and governance

Distribute responsibilities safely with role-based access delegation. Empower teams to manage day-to-day tasks while retaining oversight and control.

Important tips

  • Confirm permission scopes granted

    Review the scopes listed in the context to ensure your session has the required permissions to perform the intended Microsoft Graph operations without running into authorization errors.

  • Use the authenticated account details

    Leverage the username or service principal assigned in the context for tracking, audit, or conditional logic inside your PowerShell scripts.

  • Debug and track API requests

    Add debugging switches or inspect request logs when calling Microsoft Graph to trace any access or token issues originating from the current context.

Make everyday administrative tasks effortless with ADManager Plus

The one-stop solution to Active Directory Management and Reporting
Email Download Link Email the ADManager Plus download link