Migrating from Remove-MsolGroup to Remove-MgGroup

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.


What You Did Previously with Remove-MsolGroup

The Remove-MsolGroup cmdlet allowed administrators to delete Microsoft 365 security groups using the group’s ObjectId.

Remove Group by 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.


What You Should Do Now with Remove-MgGroup

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.

Example 1: Remove Group by ID

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

Example 2: Remove a Group with Confirmation

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

Example 3: 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
}
                            

CSV Format:

GroupId
12345678-90ab-cdef-1234-567890abcdef
abcdef12-3456-7890-abcd-ef1234567890
                            

Example 4: Removing Groups with Specific Criteria

$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.

Example 5: Using WhatIf to Preview

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

This lets you safely preview the action before making changes.


What’s Different with Remove-MgGroup?

🔄 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

Conclusion

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.



Permission Required

Example:


                                


                                


                                

© Your Site Name. All Rights Reserved. Design by HTML Codex