Managing users is a critical task for any Microsoft 365 administrator, and sometimes that includes removing users who have left the organization or no longer need access. Microsoft Graph PowerShell makes this easy with the Remove-MgUser cmdlet.
In this article, we’ll walk through everything you need to know about Remove-MgUser, including usage scenarios, syntax, and real-world examples.
Remove-MgUser is a Microsoft Graph PowerShell cmdlet that allows administrators to delete a user from Microsoft 365/Azure Active Directory. It works by identifying the user via their UserPrincipalName (email) or Object ID (GUID), then permanently removing them from the tenant.
Using New-MgGroupOwner offers many benefits:
This cmdlet is particularly useful for scripting and automation scenarios, especially when used in combination with user reports or CSV imports.
Remove-MgUser -UserId <String> [-Confirm] [-WhatIf]
Parameters:
Remove-MgUser -UserId "john.doe@contoso.com"
This deletes the user with the specified User Principal Name (UPN).
Remove-MgUser -UserId "12345abc-6789-def0-1234-56789abcdef0"
Useful when you're working with object IDs from reports or API responses.
Remove-MgUser -UserId "jane.doe@contoso.com" -Confirm
Adds a confirmation prompt before deleting the user—great for manual control.
Remove-MgUser -UserId "jane.doe@contoso.com" -WhatIf
This simulates the deletion and shows what would happen—helpful for testing scripts safely.
$users = Import-Csv "C:\Path\To\Users.csv"
foreach ($user in $users) {
Remove-MgUser -UserId $user.UserPrincipalName
}
CSV Format:
UserPrincipalName
john.doe@contoso.com
jane.doe@contoso.com
This is perfect for offboarding multiple users at once using a pre-generated CSV.
Not directly. Once a user is deleted, they move to the deleted users section in Azure AD and can be restored within 30 days, depending on your retention settings.
Unless retention or litigation hold policies are applied, the mailbox and OneDrive data will also be deleted after the retention period.
Yes, as long as you have their UserId, you can remove guest users the same way.
The Remove-MgUser cmdlet is an essential tool for every Microsoft 365 administrator. Whether you're cleaning up users manually or building automated deprovisioning pipelines, this cmdlet gives you the power and flexibility to manage user lifecycles efficiently.
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