Ernesto Gallardo
asked on
Delete Msol groups from csv file
I'm migrating all our distribution Groups that are managed from our on premises exchange server, to O365, but we are having issues with the Sync , so , some groups are not syncing correctly with O365 and are not been deleted. I need to delete then completely to re-create them later.
The only command that seems to work for me now is:
Get-MsolGroup -SearchString "Group Name" | ft *name,objectId
And then copy the object ID and do:
Remove-MsolGroup -ObjectId xxxxxxxx-xxxx-xxxx-xxxx-xx xxxxxxxxxx
I'm trying to use something like the following but is not working:
Import-CSV C:\Path\DGtodelete.csv |ForEach {Get-MsolGroup -SearchString $._Name | select *name,objectId} | Export-Csv C:\Path\objectId.csv -NoTypeInformation ### it gives me errors
Import-CSV C:\path\DGtodelete.csv | ForEach {Remove-MsolGroup -ObjectId $._ObjectId} #### also errors
Please , help me to to have this working
Thanks,
The only command that seems to work for me now is:
Get-MsolGroup -SearchString "Group Name" | ft *name,objectId
And then copy the object ID and do:
Remove-MsolGroup -ObjectId xxxxxxxx-xxxx-xxxx-xxxx-xx
I'm trying to use something like the following but is not working:
Import-CSV C:\Path\DGtodelete.csv |ForEach {Get-MsolGroup -SearchString $._Name | select *name,objectId} | Export-Csv C:\Path\objectId.csv -NoTypeInformation ### it gives me errors
Import-CSV C:\path\DGtodelete.csv | ForEach {Remove-MsolGroup -ObjectId $._ObjectId} #### also errors
Please , help me to to have this working
Thanks,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If the input csv file displays correct GUID then try..
Import-CSV C:\path\DGtodelete.csv | ForEach {$GUID = [GUID]$_.ObjectId ; Remove-MsolGroup -ObjectId $GUID}
ASKER
Ohh Yes, it worked perfectly. Thank you so much for your help. the only thing was change the file name to objectId.csv ..
Thanks again
Thanks again
ASKER
You have just saved me a lot of time and effort
You are welcome!, Don't forget to close the question! :-)
ASKER
Import-CSV C:\Cygwin\DGtodelete.csv | ForEach {Remove-MsolGroup -ObjectId $_.ObjectId}
I get this error:
Remove-MsolGroup : Cannot bind parameter 'ObjectId'. Cannot convert value "" to type "System.Guid". Error: "Unrecognized Guid format."
At line:1 char:75
+ ... win\DGtodelete.csv | ForEach {Remove-MsolGroup -ObjectId $_.ObjectId}
+ ~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Remove-MsolGroup], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgumentNoMes
And i don't understand why, it is supposed to be very simple cause if you do it one by one:
Remove-MsolGroup -ObjectId xxxxxxxx-xxxx-xxxx-xxxx-xx
Any thoughts,
Thanks again