Delete an Orphaned Microsoft Entra ID User with Graph PowerShell
Question details
The user needs to delete an orphaned user account in Microsoft Entra ID to allow a replacement Active Directory account to synchronize properly.

- Product
- Microsoft Entra ID
- Device & OS
- not provided
- Scenario
- A failed domain controller left an orphaned user in Entra ID. A new Active Directory account fails to synchronize because of the conflict, and standard removal commands appear blocked.
- Observed behavior
- The Remove-MgUser command initially fails or appears blocked because the Graph PowerShell session lacks the necessary explicit scopes (permissions) to modify or delete user objects.
Ensure you have the Microsoft Graph PowerShell module installed and possess Global Administrator or User Administrator privileges to grant consent for the required scopes.
Delete the User by Connecting with Required Scopes
To successfully delete an orphaned cloud-managed user, you must explicitly declare read and write scopes when authenticating with Microsoft Graph.
By default, connecting to Microsoft Graph PowerShell does not automatically grant the permissions needed to delete user objects. You must define the required scopes during the connection phase so Microsoft Entra ID can prompt you for administrative consent.
Open PowerShell as an Administrator and run 'Install-Module Microsoft.Graph -Scope CurrentUser' if you haven't installed it yet.
Run the command 'Connect-MgGraph -Scopes User.Read.All,User.ReadWrite.All'. A browser window will open prompting you to log in and consent to these permissions.
Find the specific user's Object ID by running '$user = Get-MgUser -Filter "userPrincipalName eq 'user@contoso.com'"', replacing the email with the actual user principal name.
Execute the deletion command by running 'Remove-MgUser -UserId $user.Id'. The user will be moved to the deleted items container.
Document Your IT Procedures Effectively with WPS Office
While PowerShell scripts handle your Microsoft Entra ID administration, WPS Office provides a lightweight, free, and highly compatible suite for documenting your IT processes, saving PowerShell guides, and managing sysadmin spreadsheets without the heavy subscription costs of Microsoft Office.
- 1. Download and Install: Visit the official WPS website to download the free suite tailored for your operating system.
- 2. Create Documentation: Open WPS Writer to draft your PowerShell scripting guides and Active Directory troubleshooting steps.
- 3. Save and Share: Save your work in standard .docx format, ensuring your IT team can easily open and read your guides.

Frequently Asked Questions
Why does Remove-MgUser return an access denied error?
This error occurs because the PowerShell session lacks the required permissions. You must explicitly define the scopes by connecting with 'Connect-MgGraph -Scopes User.ReadWrite.All' to grant the script permission to modify or delete user objects.
How can I verify the user was successfully deleted from Entra ID?
You can verify the deletion by running 'Get-MgDirectoryDeletedItem -DirectoryObjectId <UserId>' to check if the user is in the deleted items container, or by navigating to the Microsoft Entra admin center and checking the 'Deleted users' section.
Can I restore the user if I accidentally delete the wrong account?
Yes. Deleted Microsoft Entra ID users are retained in a soft-deleted state for 30 days. You can easily restore them during this window using the 'Restore-MgDirectoryDeletedItem' cmdlet or via the Entra admin center.




