Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hansgafriedzal/53bf7eef100998f14764adb493c6fb26 to your computer and use it in GitHub Desktop.
Save hansgafriedzal/53bf7eef100998f14764adb493c6fb26 to your computer and use it in GitHub Desktop.
Get Azure AD applications and their API permissions.
$searchString = ''
$_servicePrincipals = Get-AzureADServicePrincipal -All 1
[PSCustomObject] @{
Applications = Get-AzureADApplication -All 1 -SearchString $searchString | %{
$_requiredResourceAccess = $_.RequiredResourceAccess.ResourceAccess
[PSCustomObject] @{
ApplicationName = $_.DisplayName
ServicePrincipals = $_servicePrincipals | %{
[PSCustomObject] @{
ServicePrincipalName = $_.DisplayName
Permissions = `
($_requiredResourceAccess | where Type -eq Role | `
Compare-Object $_.AppRoles `
-ExcludeDifferent -IncludeEqual `
-Property Id `
-PassThru | %{
[PSCustomObject] @{
Permission = $_.Value
Type = "Application"
}
}) `
+ `
($_requiredResourceAccess | where Type -eq Scope | `
Compare-Object $_.Oauth2Permissions `
-ExcludeDifferent -IncludeEqual `
-Property Id `
-PassThru | %{
[PSCustomObject] @{
Permission = $_.Value
Type = "Delegated"
}
})
}
} | ?{$_.Permissions.Count}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment