Skip to content

Instantly share code, notes, and snippets.

@hansgafriedzal
Last active October 1, 2020 02:28
Show Gist options
  • Save hansgafriedzal/eb7687de73f4152e82fbc3b3e3ac3c66 to your computer and use it in GitHub Desktop.
Save hansgafriedzal/eb7687de73f4152e82fbc3b3e3ac3c66 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 |
+------------+--------------+--------------+
#>
$path = 'C:\'
$filename = 'group_sample.csv'
cd $path
import-csv $filename | %{
Write-Host
Write-Host "removing $($_."Group Name")... " -NoNewline
$group = Get-AzureADGroup -Filter "DisplayName eq '$($_."Group Name")'"
if ($group)
{
try
{
Remove-AzureADGroup -ObjectId $group.ObjectId
write-host "successful" -ForegroundColor Green
}
catch
{
write-host "unsuccessful" -ForegroundColor Red
write-host $_ -ForegroundColor Red
}
}
else
{
write-host "not found" -ForegroundColor Yellow
}
$csvItem = $_
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment