Last active
October 1, 2020 02:28
-
-
Save hansgafriedzal/eb7687de73f4152e82fbc3b3e3ac3c66 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 | | |
+------------+--------------+--------------+ | |
#> | |
$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