Created
February 13, 2024 00:31
-
-
Save nathanmcnulty/a9a92e41f0a5bec4b3019656a8bbe8b0 to your computer and use it in GitHub Desktop.
Convert @AshishRocks AAD script to MS Graph
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 to Microsoft Graph | |
Connect-MgGraph -Scopes Application.Read.All | |
# Get all Entra ID applications | |
$allApps = Get-MgApplication -All $true | |
$array = @() | |
# Loop through each application | |
foreach ($app in $allApps) { | |
Write-Host "Application Name: $($app.DisplayName)" | |
# Get the required resource access (application permissions) | |
$appPermissions = $app.RequiredResourceAccess | ForEach-Object { | |
$resourceAppId = $_.ResourceAppId | |
$resourceSP = Get-MgServicePrincipal -Filter "AppId eq '$resourceAppId'" | |
$_.ResourceAccess | ForEach-Object { | |
$permissionId = $_.Id | |
$permissionType = $_.Type | |
$permission = $null | |
#$resourceSP | |
if ($permissionType -eq 'Role') { | |
$permission = $resourceSP.AppRoles | Where-Object { $_.Id -eq $permissionId } | |
} elseif ($permissionType -eq 'Scope') { | |
$permission = $resourceSP.Oauth2Permissions | Where-Object { $_.Id -eq $permissionId } | |
} | |
if ($permission) { | |
[PSCustomObject]@{ | |
'Application Name' = $app.DisplayName | |
'API' = $resourceSP.DisplayName | |
'Permission Name' = $permission.Value | |
'Permission Description' = $permission.Description | |
'Permission Type' = $permissionType | |
} | |
} | |
} | |
} | |
$array+=$appPermissions | |
# Output the permissions | |
#$appPermissions | Format-Table | |
} | |
$array | Export-Csv "output.csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment