Export security group from office 365

298 Views Asked by At

I try to export my security groups, and after import and delete more than 1 groups.

$test = Get-MsolGroup | Export-Csv -path c:\temp\list.csv -encoding UTF8

After import it:

$groups= Import-Csv -Path C:\temp\test.csv

But now the format is not good for foreach script:

foreach ($group in $groups) {
 $objectID = $group.ObjectID
 Remove-MsolGroup -ObjectId $objectID
}
1

There are 1 best solutions below

3
On

Try using the AzureAD powershell commands vs the MSOL. Eventually the AzureAD modules are going away but for now this should work.

Connect-AzureAD

$test = Get-AzureADGroup | Export-Csv -path C:\temp\list.csv -encoding UTF8

$groups= Import-Csv -Path C:\temp\test.csv

foreach ($group in $groups) {
 $objectID = $group.ObjectID
 Remove-AzureADGroup -ObjectId $objectID
}