Over time, Microsoft 365 environments can become cluttered with unused or obsolete groups. Regular cleanup is crucial for keeping things organized, reducing security risks, and minimizing clutter in services like Outlook, Teams, and SharePoint.
This blog post shows you how to use the Remove-MgGroup cmdlet from Microsoft Graph PowerShell to safely and efficiently delete Microsoft 365 Groups—whether manually or in bulk.
Remove-MgGroup is a Microsoft Graph PowerShell cmdlet that allows administrators to delete a Microsoft 365 Group using its unique identifier (GUID). Once deleted, the group and its associated resources (like mailbox, Planner, Teams, etc.) are moved to a bin where they are held for 30 days after which they get permanently deleted.
Here’s why you might want to use Remove-MgGroup:
It’s a simple but powerful tool to keep your tenant clean and under control.
Remove-MgGroup -GroupId <String> [-WhatIf] [-Confirm]
Unlike update cmdlets, Remove-MgGroup does not require -BodyParameter, since it only needs the GroupId to proceed.
Note: Since deletion is permanent, always double-check the GroupId or use -WhatIf first to preview the action.
Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef"
This will immediately delete the group if no confirmation prompt is triggered (depending on session settings).
Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -Confirm
Adds a confirmation prompt before proceeding.
Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -WhatIf
Use this to preview the deletion without actually deleting anything.
Let's say you have a CSV file named groups.csv with a column GroupId:
$groups = Import-Csv -Path "C:\path\to\groups.csv"
foreach ($group in $groups) {
Remove-MgGroup -GroupId $group.GroupId -Confirm:$false
}
This silently deletes each group listed in the file.
Here’s how to delete groups that have no members:
$groups = Get-MgGroup -Filter "members/$count eq 0"
foreach ($group in $groups) {
Remove-MgGroup -GroupId $group.Id -Confirm:$false
}
Perfect for cleaning up orphaned groups.
No. Once the group is deleted, it goes to the Deleted Groups container, and you can recover it only if soft-delete is supported and recovery is done quickly.
No. Remove-MgGroup only needs the GroupId.
You need delegated or app permissions like Group.ReadWrite.All.
Yes. Deleting a Microsoft 365 Group also removes the connected resources (Team, SharePoint site, Planner, etc.).
-WhatIf
Before Deletion-WhatIf
switch with Remove-MgGroup
allows you to preview what will be deleted without actually performing the operation.
This safe practice is especially crucial in bulk deletion scenarios to prevent accidental loss of important groups.
Remove-MgGroup is a simple yet essential cmdlet for maintaining a tidy Microsoft 365 environment. Whether you're removing one group or hundreds, this Graph-powered tool helps you take full control of group lifecycle management.
Be cautious when using it—especially in bulk—and always preview with -WhatIf if you're unsure. With great power comes great responsibility!
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex