Get-MgServicePrincipal not returning anything for either AppRoles or OAuth2PermissionGrants

Johnathan Welker 106 Reputation points
2023-08-11T19:53:35.7166667+00:00

Describe the bug
Get-MgServicePrincipal doesn't return anything for the AppRoles or OAuth2PermissionGrants, despite the SP having both Delegated and App Perms assigned.

User's image

User's image

I am a Global Administrator, so I don't suspect a permission issue, especially since the rest of the object returns ok. I have run into this issue in several tenants. I also get this issue If I use the associated API as the documentation states here

Expected behavior
Per this documentation, I would expect a similar response object as the one below:

Welcome To Microsoft Graph!
Azure AD Graph service principal object and its supported permissions:
Application permissions:
AllowedMemberTypes   : {Application}
Description          : Allows the app to read applications and service principals without a signed-in user
DisplayName          : Read all applications
Id                   : 3afa6a7d-9b1a-42eb-948e-1650a849e176
IsEnabled            : True
Origin               : Application
Value                : Application.Read.All
AdditionalProperties : {}

Delegated permissions:
AdminConsentDescription : Allows users to sign in to the app, and allows the app to read the profile of signed-in users. It also allow the app to read basic company information of signed-in users.
AdminConsentDisplayName : Sign in and read user profile
Id                      : 311a71cc-e848-46a1-bdf8-97ff7156d8e6
IsEnabled               : True
Origin                  :
Type                    : User
UserConsentDescription  : Allows you to sign in to the app with your work account and let the app read your profile. It also allows the app to read basic company information.
UserConsentDisplayName  : Sign you in and read your profile
Value                   : User.Read
AdditionalProperties    : {}

Debug Output
No results to share here, as it is not returning anything at all. No errors.

Module Version

User's image

Environment Data

User's image

Screenshots
Inserted above

Additional context
For what it's worth, I'm able to return the data using Get-MgServicePrincipalAppRoleAssignment (mostly, still looking for how to return displayNames for the app perms) and Get-MgServicePrincipalOauth2PermissionGrant, but the object supposedly returned by Get-MgServicePrincipal is much easier to work with and saves me from having to make a second call. Any help is appreciated. Thanks.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,750 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,725 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
22,802 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Andy David - MVP 151.1K Reputation points MVP
    2023-08-11T21:23:18.3666667+00:00

    Hi, did you use the example provided in that doc? Using your app instead?

    This worked for me:

    Sign in with the required Application.ReadWrite.All scope

    Connect-Graph -Scopes "Application.ReadWrite.All" 
    

    Retrieve the service principal details for Azure AD Graph API.

    $AADGraph = Get-MgServicePrincipal -Filter "appId eq '00000002-0000-0000-c000-000000000000'" 
    

    Format output of the request above and display AppRoles (application permissions) and

    #oauth2PermissionScopes (delegated permissions)

    Echo "Azure AD Graph service principal object and its supported permissions:" 
    
    Echo "Application permissions:" $AADGraph.AppRoles | Format-List Echo "Delegated permissions:"
    
    $AADGraph.Oauth2PermissionScopes | Format-List
    


  2. Andy David - MVP 151.1K Reputation points MVP
    2023-08-14T18:07:28.7666667+00:00

    I think its any apps you install as an Enterprise app versus registering the app and consenting which syncs as a Service Principal. For those, I think you will have to use multiple steps to get the perms

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.