The Remove-MgDirectoryDeletedItem cmdlet permanently deletes an item from the deleted objects container in Microsoft Entra ID. When directory objects such as users, groups, or applications are deleted, they are first moved to a soft-deleted state (the recycle bin), from which they can be restored if needed. This cmdlet bypasses the recovery option and ensures that the object is hard-deleted, meaning it cannot be restored. Administrators typically use this for cleanup tasks, such as removing obsolete test accounts, decommissioned applications, or eliminating groups that should no longer exist in the environment. Since permanent deletion may also have implications for auditing and compliance, it is recommended to use this cmdlet cautiously and only when you are certain that the object should not be recovered.
This article shows how you can remove deleted objects using both Microsoft Entra admin center and Microsoft Graph PowerShell:
Use the admin portal to define trusted IP ranges or countries for your policy controls.
Ensure you have sufficient permissions and the Graph module installed:
Install-Module Microsoft.Graph -Scope CurrentUser
Connect-MgGraph -Scopes "User.ReadWrite.All", "User.Delete.All"
Run the cmdlet below by replacing
Remove-MgDirectoryDeletedItem -DirectoryObjectId
Remove-MgDirectoryDeletedItem -DirectoryObjectId "12345678-90ab-cdef-1234-567890abcdef"
Remove-MgDirectoryDeletedItem -DirectoryObjectId "12345678-90ab-cdef-1234-567890abcdef" -WhatIf
Remove-MgDirectoryDeletedItem -DirectoryObjectId "12345678-90ab-cdef-1234-567890abcd
The following are some essential parameters that can be used along with theRemove-MgDirectoryDeletedItem cmdlet:
| Parameter | Description |
|---|---|
| -DirectoryObjectId | Unique object ID of the deleted directory item to remove (required). |
| -WhatIf | Shows what would happen without performing the delete. |
| -Confirm | Prompts for confirmation before deletion. |
| -Headers | Allows sending custom HTTP headers with the request. |
ADManager Plus, an identity governance and administration solution with comprehensive Microsoft Entra ID management and reporting capabilities, simplifies complex admin tasks from a single, user-friendly console: