Last active
February 20, 2025 02:49
-
-
Save svarukala/1f473184e5ec8b36d3444ab8f5ce85e8 to your computer and use it in GitHub Desktop.
Get the delegated and application permissions for all the Azure AD Apps. The output clearly shows the roles and scopes (e.g. All.Sites.Manage, Mail.Read etc.) along with display names and resource (e.g. EXO, SPO etc.) information.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Connect-MgGraph -Scopes "User.Read.All","Group.ReadWrite.All","Application.Read.All", "Application.ReadWrite.All", "Directory.Read.All", "Directory.ReadWrite.All", "Directory.AccessAsUser.All" | |
#https://graph.microsoft.com/v1.0/applications | |
$Apps = Get-MgApplication -All | |
$permissions = @() | |
$Apps | %{ | |
$app = $_ | |
#https://graph.microsoft.com/v1.0/servicePrincipals?$filter=appId eq '00000003-0000-0ff1-ce00-000000000000' | |
#Get-MgServicePrincipal -Filter "AppId eq '00000003-0000-0ff1-ce00-000000000000'" | |
$app.RequiredResourceAccess | %{ | |
$resource = $_ | |
$rid = $resource.ResourceAppId | |
#https://graph.microsoft.com/v1.0/servicePrincipals?$filter=appId eq '00000003-0000-0ff1-ce00-000000000000' | |
$resourceSP = Get-MgServicePrincipal -Filter "AppId eq '$rid'" | |
$resource.ResourceAccess | %{ | |
$permission = $_ | |
#$permission.Id | |
#$permission.Type | |
if($permission.Type -eq 'Role'){ | |
$appRoleInfo = $resourceSP.AppRoles | where Id -eq $permission.Id | |
$permissions += [PSCustomObject] @{ | |
"AADAppName" = $app.DisplayName | |
"AADAppId" = $app.AppId | |
"PermissionType" = "Application" | |
"Resource" = $resourceSP.DisplayName | |
#"ResourceId" = $resourceSP.Id | |
"Scope" = $appRoleInfo.Value | |
#"ConsentType" = "NA" | |
"PrincipalType" = "Application" | |
#"UPN" = $userPrincipal -ne $null ? $userPrincipal.UserPrincipalName : "NA" | |
#"PrincipalId" = $userPrincipal -ne $null ? $userPrincipal.Id : "NA" | |
"SignInAudience" = $app.SignInAudience | |
} | |
} | |
elseif ($permission.Type -eq 'Scope'){ | |
$scopes = $resourceSP.Oauth2PermissionScopes | where Id -eq $permission.Id | |
$permissions += [PSCustomObject] @{ | |
"AADAppName" = $app.DisplayName | |
"AADAppId" = $app.AppId | |
"PermissionType" = "Delegated" | |
"Resource" = $resourceSP.DisplayName | |
#"ResourceId" = $resourceSP.Id | |
"Scope" = $scopes.Value | |
#"ConsentType" = "NA" | |
"PrincipalType" = $scopes.Type | |
#"UPN" = $userPrincipal -ne $null ? $userPrincipal.UserPrincipalName : "NA" | |
#"PrincipalId" = $userPrincipal -ne $null ? $userPrincipal.Id : "NA" | |
"SignInAudience" = $app.SignInAudience | |
} | |
} | |
} | |
} | |
} | |
$permissions | FT -AutoSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment