AlexSwamp
AlexSwamp

Reputation: 11

Export security group from office 365

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
}

Upvotes: 0

Views: 487

Answers (1)

Ken W - Zero Networks
Ken W - Zero Networks

Reputation: 3814

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
}

Upvotes: 0

Related Questions