If you're still using the MSOnline module's Remove-MsolGroup cmdlet to delete Microsoft 365 groups, it's time to transition to the modern and secure Microsoft Graph alternative: Remove-MgGroup. As Microsoft phases out the MSOnline module, making this shift ensures your scripts remain supported, efficient, and future-proof.
In this article, we’ll walk through what you did with Remove-MsolGroup, how to achieve the same with Remove-MgGroup, the key differences between them, and some best practices for bulk and conditional removals.
The Remove-MsolGroup cmdlet allowed administrators to delete Microsoft 365 security groups using the group’s ObjectId.
Remove-MsolGroup -ObjectId "12345678-90ab-cdef-1234-567890abcdef"
This cmdlet did its job well for years, but lacked flexibility — especially when it came to filtering, bulk actions, or dry runs.
The Graph PowerShell replacement is Remove-MgGroup, which lets you delete Microsoft 365 groups using their GroupId. It supports additional parameters for confirmation control, filter-based deletion, and previewing actions using -WhatIf.
Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef"
Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -Confirm
$groups = Import-Csv -Path "C:\\path\\to\\groups.csv"
foreach ($group in $groups) {
Remove-MgGroup -GroupId $group.GroupId -Confirm:$false
}
GroupId
12345678-90ab-cdef-1234-567890abcdef
abcdef12-3456-7890-abcd-ef1234567890
$groups = Get-MgGroup -Filter "members/$count eq 0"
foreach ($group in $groups) {
Remove-MgGroup -GroupId $group.Id -Confirm:$false
}
This is useful for cleaning up empty groups.
Remove-MgGroup -GroupId "12345678-90ab-cdef-1234-567890abcdef" -WhatIf
This lets you safely preview the action before making changes.
🔄 Old (Remove-MsolGroup) | ➡️ New (Remove-MgGroup) |
Uses -ObjectId | Uses -GroupId |
No support for -WhatIf | Supports -WhatIf for previewing deletions |
Part of deprecated MSOnline module | Part of Microsoft.Graph.Groups module |
Lacks filtering or rich queries | Can combine with Get-MgGroup -Filter |
Migrating from Remove-MsolGroup to Remove-MgGroup is more than just a syntax update — it unlocks better automation, previewing capabilities, and Graph-powered flexibility. With support for CSV-driven and condition-based deletions, Remove-MgGroup makes group cleanup and lifecycle management easier than ever.
Whether you’re decommissioning old security groups or maintaining a clean group directory, this cmdlet is your modern tool for the task.
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