Deleting Microsoft Entra ID users is a critical administrative task driven by various needs, including revoking access for ex-employees, cleaning up inactive users, security, and compliance. While Graph PowerShell's Remove-MgUser command, an alternative to the New-AzureADUser command, can be used to delete Microsoft Entra ID users, its complexity and non-intuitive interface make it a challenging option. On the other hand, ADManager Plus, a Microsoft 365 management and reporting tool, simplifies this process, allowing administrators to quickly delete users in just a few clicks.
Before using the Remove-MgUser cmdlet, ensure the following:
Install-Module Microsoft.Graph -Scope CurrentUser
User.DeleteRestore.All,
User.ReadWrite.All,
DeviceManagementServiceConfig.ReadWrite.All,
DeviceManagementManagedDevices.ReadWrite.All,
DeviceManagementConfiguration.ReadWrite.All,
DeviceManagementApps.ReadWrite.All,
The Remove-MgUser cmdlet can be used in Microsoft Graph PowerShell to delete Microsoft Entra ID users. Here's the syntax:
Remove-MgUser
-UserId <String>
[-IfMatch <String>]
[-ResponseHeadersVariable <String>]
[-Headers <IDictionary>]
[-PassThru]
[-ProgressAction <ActionPreference>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Example 1: Remove a user
This script removes a user.
Remove-MgUser -UserId '5c442efb-5e66-484a-936a-91b6810bed14'
Example 2: Remove a user with a confirmation
This script removes a user after the user is prompted for a confirmation.
Remove-MgUser -UserId '3f80a75e-750b-49aa-a6b0-d9bf6df7b4c6' -Confirm
The following table contains some parameters that can be used along with the Remove-MgUser command to efficiently delete Microsoft Entra ID users.
| Parameters | Description |
|---|---|
| -Headers | This parameter allows you to add optional headers to the request. |
| -PassThru | This parameter returns true when the command succeeds. |
| -ResponseHeadersVariable | This parameter allows you to add option response header variables. |
| -UserId | This parameter displays the unique identifier of the user. |
| -WhatIf | This parameter displays the outcome if the cmdlet is executed. |