Summary


A group or contact needs to be deleted from 365 using PowerShell but remove-msolcontact or group doesn't work.



Cause


Groups or contacts need to be removed by using the object ID.



Solution


As a customers 365 tenancy may include hundreds or possible thousands of groups it's best to export a list of them all to your local machine.


Login to their 365 tenancy using Azure PowerShell and change the root folder location to one on your local machine, in the example below it's going to a folder on the C drive names IAM Cloud.


You can do this by using the command cd C:\IAM Cloud


goWzszANt6RIVi_K5IV0DlD-Ru1AzfsS7A.png


Then use one of these commands:


get-msolgroup -all | export-csv Dundalkgroups.csv –NoTypeInformation

get-msolcontact -all | export-csv Dundalkcontacts.csv –NoTypeInformation


Name the .csv something relevant to the customer.


OQYgTDiaDOHOJu0Z1TXbXdD66iJCuCdCqw.png


This will save to the local folder:


C1ahhX2nujut3aEAIoXZkoeC9swjOlOGdw.png



From the spreadsheet delete any columns that you don't need and find the correct group or contact either by display name or email address:


A7hxIM9ZZh-92EQ7DXZLsh2tF4dPHt2Wew.png


Then the command you need to run is remove-msolgroup -objectID 'insert object ID' or remove-msolcontact -objectID 'insert objectID'.


This will permanently remove the group or contact.