As Microsoft deprecates the AzureAD module in favor of the Microsoft Graph PowerShell SDK, administrators must transition their scripts and automation tools. One commonly used cmdlet for removing Microsoft 365 groups is Remove-AzureADGroup.
This article will guide you through migrating to the modern Remove-MgGroup cmdlet and how to use it for various scenarios like single deletion, bulk removal, conditional deletion, and dry-run previews.
The AzureAD module allowed administrators to remove Microsoft 365 groups using their group object IDs.
Example
Remove-AzureADGroup -ObjectId "12345678-90ab-cdef-1234-567890abcdef"
This command removed the specified group without asking for confirmation (unless specified).
The Graph PowerShell equivalent is Remove-MgGroup, which offers the same functionality, but with better extensibility and alignment to the Microsoft Graph API.
Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef"
Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -Confirm
CSV File Format
GroupId
12345678-90ab-cdef-1234-567890abcdef
abcdef12-3456-7890-abcd-ef1234567890
$groups = Import-Csv -Path "C:\path\to\groups.csv"
foreach ($group in $groups) {
Remove-MgGroup -GroupId $group.GroupId
}
This script removes all groups listed in the CSV file without prompting for confirmation.
Let’s say you want to remove all groups that have zero members:
$groups = Get-MgGroup -Filter "members/$count eq 0"
foreach ($group in $groups) {
Remove-MgGroup -GroupId $group.Id
}
Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -WhatIf
This preview shows what would happen if you ran the removal, without executing it — great for validation.
Legacy Cmdlet | Modern Cmdlet |
Remove-AzureADGroup | Remove-MgGroup |
Uses -ObjectId | Uses -GroupId |
AzureAD module | Microsoft.Graph.Groups |
No support for -WhatIf | Supports -WhatIf, -Confirm, and more |
Less extensible | Fully extensible via Graph |
Tip: Always test with -WhatIf before running deletion scripts, especially in bulk.
Migrating from Remove-AzureADGroup to Remove-MgGroup is straightforward, and the benefits are significant. With modern security, better extensibility, and strong scripting support, Graph PowerShell ensures you stay compliant and future-ready.
Make the shift today to future-proof your scripts and embrace the power of Microsoft Graph. Visit M365Corner.com for ready-to-use free Microsoft Graph PowerShell tools and step-by-step migration guides built for Microsoft 365 administrators.
© Your Site Name. All Rights Reserved. Design by HTML Codex