Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitWhen a Microsoft 365 user or group is deleted in Azure AD (Entra ID), it moves to the Deleted Items container for a limited retention period (typically 30 days). If you’re certain you no longer need a deleted object, you can permanently delete it using the Remove-MgDirectoryDeletedItem cmdlet. This ensures it cannot be restored and is completely removed from the tenant.
Remove-MgDirectoryDeletedItem -DirectoryObjectId <directory-object-id>
Required scope (recommended):
Connect-MgGraph -Scopes "Directory.ReadWrite.All"
Use the appropriate helper cmdlet based on the object type you want to permanently delete.
# List deleted users and pick one
Get-MgDirectoryDeletedItemAsUser |
Select-Object Id, DisplayName, UserPrincipalName, DeletedDateTime |
Sort-Object DeletedDateTime -Descending
# List deleted groups and pick one
Get-MgDirectoryDeletedItemAsGroup |
Select-Object Id, DisplayName, Mail, GroupTypes, DeletedDateTime |
Sort-Object DeletedDateTime -Descending
Copy the Id of the directory object you wish to permanently delete.
Remove-MgDirectoryDeletedItem -DirectoryObjectId ae22d08d-1ef5-4ac0-b36b-376864f6b63a
After permanent deletion, the object will no longer appear in deleted items:
Get-MgDirectoryDeletedItemAsUser # Should return nothing
You can remove all soft deleted Microsoft 365 Directory Objects by piping the results from Get-MgDirectoryDeletedItemAsUser or Get-MgDirectoryDeletedItemAsGroup to Remove-MgDirectoryDeletedItem cmdlet and looping through each item in the list using a ForEach-Object cmdlet.
You can also confirm the deletion by running Get-MgDirectoryDeletedItemAsUser or Get-MgDirectoryDeletedItemAsGroup, depending on your requirements.
Get-MgDirectoryDeletedItemAsUser -All | ForEach-Object { Remove-MgDirectoryDeletedItem -DirectoryObjectId $_.Id -Confirm:$false }
| Error | Likely Cause | How to Fix |
|---|---|---|
| Authorization_RequestDenied or Insufficient privileges to complete the operation. | You’re missing admin privileges or required Graph permissions. | Reconnect with Connect-MgGraph -Scopes "Directory.ReadWrite.All" and ensure you’re a Global Admin or Directory Admin. |
| ResourceNotFound | The provided ID does not exist or is already permanently deleted. | Run Get-MgDirectoryDeletedItemAsUser or Get-MgDirectoryDeletedItemAsGroup again to fetch current IDs. |
| Forbidden | The account or app lacks directory write permissions. | Grant Directory.ReadWrite.All admin consent for the signed-in account or service principal. |
| BadRequest | Incorrect or invalid Directory Object ID format. | Double-check the ID value—it must be a valid GUID. |
| OperationNotAllowed | Trying to remove an object that is currently being restored or synced. | Wait until the restore or sync process completes, then retry the deletion. |
Remove-MgDirectoryDeletedItem is the final step in managing the lifecycle of directory objects within Azure AD. It allows administrators to permanently delete users or groups that no longer need retention in the Deleted Items container. Always verify the object ID and ensure you truly intend to delete it, as this action cannot be undone. Use this cmdlet judiciously for effective directory hygiene and compliance management.
© m365corner.com. All Rights Reserved. Design by HTML Codex