How to Use Remove-MgGroup to Delete Microsoft 365 Groups?

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.

What is Remove-MgGroup?

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.

Why Use Remove-MgGroup?

Here’s why you might want to use Remove-MgGroup:

  • To clean up inactive or empty groups
  • To automate group lifecycle management
  • To bulk delete test or temporary groups
  • To enforce naming policies or compliance

It’s a simple but powerful tool to keep your tenant clean and under control.

Cmdlet Syntax

Remove-MgGroup -GroupId <String> [-WhatIf] [-Confirm]

Unlike update cmdlets, Remove-MgGroup does not require -BodyParameter, since it only needs the GroupId to proceed.

Usage Examples

Note: Since deletion is permanent, always double-check the GroupId or use -WhatIf first to preview the action.

Example 1: Remove a Group by ID

Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef"

This will immediately delete the group if no confirmation prompt is triggered (depending on session settings).

Example 2: Remove a Group with Confirmation

Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -Confirm

Adds a confirmation prompt before proceeding.

Example 3: Check What If Without Removing

Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -WhatIf

Use this to preview the deletion without actually deleting anything.

Example 4: Bulk Remove Groups from a CSV File

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.

Example 5: Removing Groups with Specific Criteria

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.

Frequently Asked Questions

  • Can I undo a Remove-MgGroup operation?
  • 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.

  • Do I need -BodyParameter to delete a group?
  • No. Remove-MgGroup only needs the GroupId.

  • What permissions are needed?
  • You need delegated or app permissions like Group.ReadWrite.All.

  • Will this also delete Microsoft Teams or Planner associated with the group?
  • Yes. Deleting a Microsoft 365 Group also removes the connected resources (Team, SharePoint site, Planner, etc.).

Use Cases

  • Automated cleanup of old or unused Microsoft 365 Groups
  • Bulk deletion of test groups post-migration or training
  • Policy enforcement, such as removing non-compliant group names or tags
  • Security auditing and removal of externally shared or public groups
🛑 Always Test with -WhatIf Before Deletion

Using the -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.
📋 Bulk Deletion Scripts Should Log Each Operation

When deleting multiple groups via scripts, incorporate logging (e.g., writing to a CSV or log file) to track which groups were processed, deleted, or skipped. This makes post-deletion audits and troubleshooting much easier.

Conclusion

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