Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hansgafriedzal/50985ae83d8dc947107f0347b693232e to your computer and use it in GitHub Desktop.
Save hansgafriedzal/50985ae83d8dc947107f0347b693232e to your computer and use it in GitHub Desktop.
<#
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