The Remove-MgUser cmdlet in Microsoft Graph PowerShell is used to delete a user account from Microsoft 365. It can target accounts using either the user’s unique ID (GUID) or their User Principal Name (UPN).
Automating user removal with Remove-MgUser allows administrators to quickly deprovision accounts in bulk, ensuring faster offboarding, maintaining security, and preventing unauthorized access without manually navigating the Microsoft 365 admin center.
Before using Remove-MgGroup, ensure you have the Microsoft Graph PowerShell module installed and the necessary permissions granted.
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "Group.ReadWrite.All"
Remove-MgUser -UserId <userid>
The cmdlet can be used with a UPN or the unique user ID. It supports preview mode with -WhatIf and confirmation prompts with -Confirm for safer execution.
Remove-MgUser -UserId "john.doe@contoso.com"
Remove-MgUser -UserId "12345abc-6789-def0-1234-56789abcdef0"
Remove-MgUser -UserId "jane.doe@contoso.com" -Confirm
Remove-MgUser -UserId "jane.doe@contoso.com" -WhatIf
$users = Import-Csv "C:\Path\To\Users.csv"
foreach ($user in $users) {
Remove-MgUser -UserId $user.UserPrincipalName
}
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