Skip to content

Instantly share code, notes, and snippets.

@pmatthews05
Created June 18, 2020 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pmatthews05/51c9211297f2bd7bd8c6e2071e609840 to your computer and use it in GitHub Desktop.
Save pmatthews05/51c9211297f2bd7bd8c6e2071e609840 to your computer and use it in GitHub Desktop.
#Get a access Token
$tokenResponse = az account get-access-token --resource-type ms-graph | convertFrom-Json
#Get all App Role Assignment Permission for the Service prinipal ObjectId.
$apiUrl = "https://graph.microsoft.com/v1.0/servicePrincipals/$ServicePrincipalObjectId/appRoleAssignments"
$appRoleAssignmentCollection = @(Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization = "Bearer $($tokenResponse.accessToken)" } -Method GET -ContentType "application/json").value
$appRoleAssignmentCollection | ForEach-Object {
$appRoleAssignment = $PSItem
$deleteApiUrl = "$apiUrl/$($appRoleAssignment.id)"
Invoke-RestMethod -Uri $deleteApiUrl -Headers @{Authorization = "bearer $($tokenResponse.accessToken)" } -Method Delete -ContentType "application/json"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment