Accidentally deleted a user in Microsoft 365? Don’t worry — you can restore them easily using Microsoft Graph PowerShell. This guide walks you through what user restore means, why it's important, and how to do it step by step with a simple PowerShell command.
User restore refers to the process of bringing back a user account that was deleted from Microsoft 365 (Azure AD). When a user is deleted, their account moves to a soft-deleted state, where it can still be recovered within 30 days.
Restoring the user brings back their account, group memberships, and many associated settings.
There are several reasons you might need to restore a user:
Restoring a deleted user is simple with the Restore-MgDirectoryDeletedItem cmdlet.
Connect-MgGraph -Scopes "Directory.AccessAsUser.All"
Run Get-MgDirectoryDeletedItemAsUser cmdlet to get the ID of the deleted user:
Get-MgDirectoryDeletedItemAsUser
Use the Object ID from the previous step to restore the user:
Restore-MgDirectoryDeletedItem -DirectoryObjectId "c71e4a5f-e379-4389-8f6e-af9057860fa1"
Replace the GUID above with your actual user’s DirectoryObjectId.
Here’s where restoring a user is incredibly helpful:
Error Message | Cause | Solution |
Access Denied | Missing required permission | Connect using: Connect-MgGraph -Scopes "Directory.AccessAsUser.All" |
Directory object not found | User may be permanently deleted or ID is incorrect | Ensure the user is still in the deleted list and the ID is correct |
Restore failed due to policy restrictions | Conditional access or policy limitations in place | Review Azure AD policies or attempt restore via the Microsoft 365 portal |
Restoring deleted users in Microsoft 365 is straightforward with Graph PowerShell. By using the Restore-MgDirectoryDeletedItem cmdlet, you can quickly bring back user accounts without needing to recreate them from scratch.
Whether you’re fixing an accidental deletion or bringing someone back for a project, this script makes it easy and efficient.
Give it a try and streamline your recovery process!
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