Created
September 30, 2020 17:21
-
-
Save hansgafriedzal/50985ae83d8dc947107f0347b693232e to your computer and use it in GitHub Desktop.
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
<# | |
CSV FORMAT | |
+------------+--------------+--------------+ | |
| Group Name | Group Owner1 | Group Owner2 | | |
+------------+--------------+--------------+ | |
| group1 | user@domain | user@domain | | |
| group2 | user@domain | user@domain | | |
| group3 | user@domain | user@domain | | |
+------------+--------------+--------------+ | |
#> | |
cls | |
$appId = '' | |
$appRoleName = '' | |
$path = '' | |
$filename = '' | |
Write-Host "searching app $($appName)... " -NoNewline | |
$sp = Get-AzureADServicePrincipal -ObjectId $appId | |
if ($sp) | |
{ | |
Write-Host "object id" $sp.ObjectId | |
cd $path | |
$groups = import-csv $filename | |
Get-AzureADServiceAppRoleAssignment -ObjectId $sp.ObjectId -All 1 | where PrincipalType -eq Group | %{ | |
Write-Host "searching group $($_.PrincipalDisplayName)... " -NoNewline | |
if ($groups."Group Name" -contains $_.PrincipalDisplayName) | |
{ | |
Write-Host "object id" $_.ObjectId | |
Write-Host "removing assignment... " -NoNewline | |
try | |
{ | |
Remove-AzureADGroupAppRoleAssignment -ObjectId $_.PrincipalId -AppRoleAssignmentId $_.ObjectId | |
Write-Host "successful" -ForegroundColor Green | |
} | |
catch | |
{ | |
Write-Host "unsuccessful" -ForegroundColor Red | |
Write-Host $_ -ForegroundColor Red | |
} | |
} | |
else | |
{ | |
Write-Host "not found" -ForegroundColor Red | |
} | |
} | |
} | |
else | |
{ | |
Write-Host "not found" -ForegroundColor Red | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment