The Restore-MgDirectoryDeletedItem cmdlet in Microsoft Graph PowerShell restores a previously deleted directory object such as a user, group, or application that exists in the Microsoft Entra ID (formerly Azure Active Directory) recycle bin. This cmdlet is particularly useful for recovering users or groups that were accidentally deleted or removed during bulk operations.
Administrators use this cmdlet to recover deleted directory objects without data loss. It helps restore user accounts, group memberships, and associated properties that remain intact during the soft-delete retention period (typically 30 days).
Key benefits include:
Before using this cmdlet, install the Microsoft Graph module and connect with the appropriate scopes based on the object type you wish to restore.
For users:
Connect-MgGraph -Scopes "User.DeleteRestore.All"
For restoring groups:
Connect-MgGraph -Scopes "Group.ReadWrite.All"
You must provide the DirectoryObjectId of the deleted item to restore it. The ID can be retrieved using the Get-MgDirectoryDeletedItem cmdlet.
Syntax:
Restore-MgDirectoryDeletedItem -DirectoryObjectId <directory-object-id>
Example: Restore a deleted directory object
Restore-MgDirectoryDeletedItem -DirectoryObjectId ae22d08d-1ef5-4ac0-b36b-376864f6b63a
This command restores the deleted directory object (such as a user or group) with the specified DirectoryObjectId from Microsoft Entra ID’s recycle bin.
| Key Point | Details |
|---|---|
| Cmdlet Name | Restore-MgDirectoryDeletedItem |
| Purpose | Restores soft-deleted directory objects such as users or groups |
| Required Scope | User.DeleteRestore.All or Group.ReadWrite.All |
| Primary Parameter | DirectoryObjectId |
| Automation Benefit | Enables administrators to automate recovery of deleted users or groups |
| Use Case | Quickly restore accidentally deleted accounts or groups from Microsoft Entra ID |
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