Remove-MgGroup

What is Remove-MgGroup?

Remove-MgGroup is a Microsoft Graph PowerShell cmdlet that deletes Microsoft 365 groups, including Office 365 Groups, Security Groups, and Microsoft Teams–backed groups. It helps administrators clean up unused or redundant groups in their tenant.


Why Use Remove-MgGroup?

Group sprawl can quickly become a challenge in M365 environments. With Remove-MgGroup, admins can automate group cleanup, ensuring a secure and clutter-free directory. Automating group removal saves time, reduces errors, and enforces governance policies across large-scale environments.

Prerequisites

Before using Remove-MgGroup, install the Microsoft Graph PowerShell module and connect with the right permissions.

Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "Group.ReadWrite.All"

How to Use Remove-MgGroup?

Syntax:

Remove-MgGroup -GroupId <group-id>

The cmdlet requires the GroupId parameter. It can be used with confirmation prompts, safety checks, or bulk scripts for mass group deletion.


Remove-MgGroup Examples

  • Remove a Group by ID
  • Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef"
  • Remove a Group with Confirmation
  • Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -Confirm
  • Check What If Without Removing
  • Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -WhatIf
  • Remove Groups with Specific Criteria
  • $groups = Get-MgGroup -Filter "members/$count eq 0"
    foreach ($group in $groups) {
        Remove-MgGroup -GroupId $group.Id 
    }
                                                
  • Bulk Remove Groups from a CSV File
  • $groups = Import-Csv -Path "C:\path\to\groups.csv"
    foreach ($group in $groups) {
        Remove-MgGroup -GroupId $group.GroupId -Confirm:$false
    }
                                                

✅ This cmdlet is best suited for administrators managing lifecycle policies and automating cleanup of unused M365 groups.


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