How to get service principal OAuth2 permission grants using Microsoft Graph PowerShell

The Get-MgServicePrincipalOauth2PermissionGrant cmdlet retrieves all OAuth2 delegated permission grants that have been assigned to a service principal in Microsoft Entra ID (formerly Azure AD). By running this cmdlet, admins can identify which permissions have been consented to, who consented to them, and whether the consent was granted tenant-wide or user level. This is beneficial for security reviews, compliance audits, and troubleshooting, as excessive or misconfigured permissions could introduce risks.

This article shows you how to view OAuth2 permission grants using both the Microsoft Entra admin center and Microsoft Graph PowerShell:

View OAuth2 permission grants using Microsoft Entra admin center

OAuth2 grants can be reviewed under each enterprise application's Permissions section.

  1. Navigate to Microsoft Entra admin center.
  2. Select Azure Active Directory > Enterprise applications.
  3. Choose the application and look under Permissions.

Get OAuth2 permission grants using Microsoft Graph PowerShell

Prerequisites

Install Microsoft Graph module and connect with app role assignment read scope:

Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "AppRoleAssignment.Read.All"

Using the Get-MgServicePrincipalOauth2PermissionGrant cmdlet

Run the command below with the service principal ID:

Get-MgServicePrincipalOauth2PermissionGrant -ServicePrincipalId <sp-id>

Examples

Example 1: List all OAuth2 permission grants

Get-MgServicePrincipalOauth2PermissionGrant -ServicePrincipalId "abcdef12-3456-7890-abcd-ef1234567890"

Example 2: Filter grants by specific resource

Get-MgServicePrincipalOauth2PermissionGrant -ServicePrincipalId "abcdef12-3456-7890-abcd-ef1234567890" -Filter "resourceId eq 'resource-guid'"

Example 3: Limit results to top five grants

Get-MgServicePrincipalOauth2PermissionGrant -ServicePrincipalId "abcdef12-3456-7890-abcd-ef1234567890" -Top 5

Supported parameters

The following are some essential parameters that can be used along with the Get-MgServicePrincipalOauth2PermissionGrant cmdlet:

Parameter Description
-ServicePrincipalId The object ID of the service principal whose grants to retrieve.
-Filter An OData filter expression to refine returned grants.
-Top Limits the number of grants returned.
-All Retrieves all results by paging.
-Property Selects properties to include in the results.

Limitations of using native tools to view OAuth2 permission grants

  • PowerShell commands can get complex with different use cases and scenarios.
  • IT admins can spend a lot of time troubleshooting errors, which in turn negatively impacts productivity.
  • Delegation can get tricky since technicians require elevated permissions.

How ADManager Plus helps you manage Microsoft Entra ID

ADManager Plus, an identity governance and administration solution with comprehensive Microsoft Entra ID management and reporting capabilities, simplifies complex admin tasks from a single, user-friendly console:

Perform script-free Microsoft Entra ID management and reporting with ADManager Plus

 
  • View OAuth2 permission grants using Microsoft Entra admin center
  • Get OAuth2 permission grants using Microsoft Graph PowerShell
  • Examples
  • Supported parameters
  • Limitations of using native tools to view OAuth2 permission grants
  • How ADManager Plus helps you manage Microsoft Entra ID
The one-stop solution to Active Directory Management and Reporting
Email Download Link Email the ADManager Plus download link