Remove Deleted Directory Items | Microsoft Graph PowerShell
 
 
 

How to remove deleted directory items using Microsoft Graph PowerShell

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:

  • M365 admin center
  • PowerShell
 

Remove deleted objects using Microsoft Entra admin center

Use the admin portal to define trusted IP ranges or countries for your policy controls.

  1. Go to Microsoft Entra admin center.
  2. Go to Users > Deleted users (or the appropriate deleted items section).
  3. Select the object and choose Delete permanently.

Remove deleted directory items using Microsoft Graph PowerShell

Prerequisites

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"

Using the Remove-MgDirectoryDeletedItem cmdlet

Run the cmdlet below by replacing with the deleted object's ID.

Remove-MgDirectoryDeletedItem -DirectoryObjectId

Examples

Example 1: Permanently delete a user

Remove-MgDirectoryDeletedItem -DirectoryObjectId "12345678-90ab-cdef-1234-567890abcdef"

Example 2: Preview deletion without executing

Remove-MgDirectoryDeletedItem -DirectoryObjectId "12345678-90ab-cdef-1234-567890abcdef" -WhatIf

Example 3: Confirm before deleting

Remove-MgDirectoryDeletedItem -DirectoryObjectId "12345678-90ab-cdef-1234-567890abcd

Supported parameters

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.

Limitations of using native tools to remove deleted objects

  • PowerShell commands can get complex with different use cases and scenarios.
  • IT admins can spend a lot of time troubleshooting errors, which negatively impacts productivity.
  • Delegation can get tricky since technicians require elevated permissions.

How ADManager Plus helps you manage Microsoft Entra ID

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:

Perform script-free Microsoft Entra ID management and reporting with ADManager Plus

The one-stop solution to Active Directory Management and Reporting
Email Download Link Email the ADManager Plus download link