Others

Delete an Orphaned Microsoft Entra ID User with Graph PowerShell

Steve KSteve K Sep 29, 2026 871 views

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.

How to Delete an Orphaned Microsoft Entra ID User with Graph PowerShell
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.
Before you start

Ensure you have the Microsoft Graph PowerShell module installed and possess Global Administrator or User Administrator privileges to grant consent for the required scopes.

Solution 1Recommended

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.

1
Install Microsoft Graph PowerShell

Open PowerShell as an Administrator and run 'Install-Module Microsoft.Graph -Scope CurrentUser' if you haven't installed it yet.

2
Connect with Explicit Scopes

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.

3
Locate the Orphaned User

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.

4
Remove the User

Execute the deletion command by running 'Remove-MgUser -UserId $user.Id'. The user will be moved to the deleted items container.

Connection Successful: Adding the '-Scopes User.ReadWrite.All' parameter resolves the access denial issue, allowing the Remove-MgUser cmdlet to execute successfully.
Free Microsoft Office alternative

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. 1. Download and Install: Visit the official WPS website to download the free suite tailored for your operating system.
  2. 2. Create Documentation: Open WPS Writer to draft your PowerShell scripting guides and Active Directory troubleshooting steps.
  3. 3. Save and Share: Save your work in standard .docx format, ensuring your IT team can easily open and read your guides.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx) for seamless documentation sharing.Free and lightweight suite, perfect for IT administrators needing quick, responsive access to local files.Built-in PDF editing tools for creating secure administration guides, network diagrams, and reports.Familiar tabbed interface allows you to manage multiple administrative documents in a single window.
microsoft office alternative - wps office

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.