Powershell: Deleting Users in Microsoft 365
Intro
Prerequisites
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "User.ReadWrite.All", "Directory.ReadWrite.All"Delete a Single User by Email or ID
By UserPrincipalName:
Remove-MgUser -UserId "user@example.com"By Object ID:
Bulk Delete Users (Except Admin)
Targeted Deletion Examples
Delete users from a specific domain:
Delete unlicensed users only:
Optional: Hard Delete from the Recycle Bin
Summary
REFERENCES
Last updated