How to Restore Microsoft 365 User Using Graph PowerShell?

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.

What is User Restore?

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.

Why Restore a Deleted User?

There are several reasons you might need to restore a user:

  • Accidental Deletion: Admins or automated scripts may remove the wrong account.
  • License Reassignment: Reinstating users with their original configurations saves time.
  • Security Hold: Restore an account for investigation or compliance purposes.
  • Temporary Employees: Reactivate seasonal or project-based staff accounts.

How to Restore a User Using Graph PowerShell

Restoring a deleted user is simple with the Restore-MgDirectoryDeletedItem cmdlet.

  1. Connect to Microsoft Graph
  2. Connect-MgGraph -Scopes "Directory.AccessAsUser.All"
  3. Find the Deleted User
  4. Run Get-MgDirectoryDeletedItemAsUser cmdlet to get the ID of the deleted user:

    Get-MgDirectoryDeletedItemAsUser
  5. Restore the User
  6. 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.

Use Cases

Here’s where restoring a user is incredibly helpful:

  1. Undo Accidental Deletions: Sometimes administrators or automation tools mistakenly delete active users. Restoring the user immediately minimizes business disruption and avoids reconfiguration.
  2. Business Continuity: During organizational changes, mergers, or internal restructuring, users may be deleted prematurely. Restoring them ensures that business operations and project access are not interrupted.
  3. Security Audits: Restoring a user temporarily for investigative purposes — such as retrieving data, email records, or access logs — can help meet audit or forensic needs without creating a new identity.
  4. Rehire or Reengagement: When former employees return to the organization, restoring their previous account allows them to pick up where they left off — with access to previous emails, documents, and group memberships.
  5. Testing and Training Accounts: Accounts used for testing or employee onboarding simulations may be deleted and later needed again. Restoring these accounts helps save setup time.
  6. Compliance Requirements In certain industries, retaining or retrieving user data is mandated. Restoring a deleted user helps fulfill these obligations quickly.

Possible Errors and solutiion

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

Conclusion

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