Deleting a group with PowerShell

You usually delete an old distribution list or Microsoft 365 group in the admin center. If you need to clean up many at once, or want it in a script, PowerShell is faster. Here's how, and how to undo a mistake.

Connect

Connect-ExchangeOnline

Read install the Exchange Online module.

Delete a Microsoft 365 group

Get-UnifiedGroup -Identity "Project team X" | Select DisplayName, PrimarySmtpAddress
Remove-UnifiedGroup -Identity "Project team X"

Careful: this also deletes the group's team in Teams, its SharePoint site, mailbox and plan.

Deleting a Microsoft 365 group with PowerShell

Delete a distribution group

Remove-DistributionGroup -Identity "sales@yourdomain.com"

Type Y to confirm, or add -Confirm:$false in a script.

Deleting a distribution group

With Microsoft Graph

Connect-MgGraph -Scopes "Group.ReadWrite.All"
Get-MgGroup -Filter "displayName eq 'Project team X'" | Select Id, DisplayName
Remove-MgGroup -GroupId <Id>
Groups in Microsoft Entra

Deleted too soon?

Restoring deleted groups

Also see PowerShell for Microsoft 365 and create a distribution list.

Nederlandstalige versie: Een Microsoft 365-groep of distributiegroep verwijderen met PowerShell


Related articles