Solved

Delete Msol groups from csv file

Posted on 2016-10-04
6
76 Views
Last Modified: 2016-10-04
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-xxxxxxxxxxxx
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,
0
Comment
Question by:Ernesto Gallardo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 41828413
It could be the syntax error.. $._ObjectId will give error..  $_.ObjectId should correct it
Import-CSV C:\Path\DGtodelete.csv |ForEach {Get-MsolGroup -SearchString $_.Name | select name,objectId} | Export-Csv C:\Path\objectId.csv -NoTypeInformation

Import-CSV C:\path\DGtodelete.csv | ForEach {Remove-MsolGroup -ObjectId $_.ObjectId}

Open in new window

1
 

Author Comment

by:Ernesto Gallardo
ID: 41828465
Thank you very much for your help. For the first one it worked perfectly , It created the objectId.csv file with the objectId for every DG in DGtodelete.csv. So when i run the second one :

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 : CannotConvertArgumentNoMessage,Microsoft.Online.Administration.Automation.RemoveGroup
 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-xxxxxxxxxxxx   ...It works fine
 Any thoughts,
Thanks again
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41828478
If the input csv file displays correct GUID then try..
Import-CSV C:\path\DGtodelete.csv | ForEach {$GUID = [GUID]$_.ObjectId ; Remove-MsolGroup -ObjectId $GUID}

Open in new window

1
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

Author Comment

by:Ernesto Gallardo
ID: 41828519
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
0
 

Author Comment

by:Ernesto Gallardo
ID: 41828525
You have just saved me a lot of time and effort
0
 
LVL 40

Expert Comment

by:Subsun
ID: 41828590
You are welcome!, Don't forget to close the question! :-)
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question