List all Office 365 Groups & Delete Office 365 Groups

In the tenant using Modern Authentication and/or multi-factor authentication (MFA), connect to the Exchange Online PowerShell Module to work with groups.

  • Use IE/Edge (don’t skip), go to the Exchange admin center
  • Go to Hybrid > Click the second configure >
  • In the PowerShell window enter the following to connect. Details docs are in the reference links.

Connect-EXOPSSession -UserPrincipalName

To list all Office 365:


View all the properties of the group:

Get-UnifiedGroup -Identity "My Group Name" | Format-List

Note: ExternalDirectoryObjectId is same as other group Ids (e.g. Teams GUID).

Selected properties can be exported to excel file:

Get-UnifiedGroup | Select-Object -Property DisplayName, GroupType, ExternalDirectoryObjectId, PrimarySmtpAddress, Name | Export-Csv -Path .\ExportGroups.csv -NoTypeInformation

After manipulating the excel files, the same file can be used to delete/clean-up test/unwanted Groups:

Import-CSV .\ExportGroups.csv | Foreach-Object{
Write-Host "Deleting" $_.Name
Remove-UnifiedGroup -Identity $_.Name -confirm:$false

The above is a soft-delete of the groups and will be retained for another 30 days (for admin to restore). To reuse the same group internal name, those groups need to be permanently deleted. We will need to use AzureAD PowerShell Module for this. Run the following commands and sign-in again to see the list of deleted groups.

Import-Module AzureADPreview
#The list can be exported in a excel for curation.
Get-AzureADMSDeletedGroup | Select-Object -Property DisplayName, ID | Export-Csv -Path .\DeletedGroups.csv -NoTypeInformation

After modifying the export file, same can be used to permanently delete those groups.

Import-CSV .\DeletedGroups.csv | Foreach-Object{
Write-Host "Permanently deleting" $_.DisplayName
Remove-AzureADMSDeletedDirectoryObject -Id $_.ID

Issues: if you are getting the following error, you have missed the step highlighted above in red. Use IE/Edge.
You cannot start application Microsoft Exchange Online Powershell Module from this location because it is already installed from a different location.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s