Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitThe Get-MgDirectoryDeletedItemAsGroup cmdlet in Microsoft Graph PowerShell helps administrators view and manage deleted Microsoft 365 groups that are currently in a soft-deleted state.
When a Microsoft 365 group (or Microsoft Team) is deleted, it isn’t immediately removed from your tenant. Instead, it’s retained in the Azure AD recycle bin for 30 days, allowing you to restore or permanently delete it during that retention period.
This cmdlet is essential for identifying deleted groups and retrieving their Group IDs, which are required when restoring or permanently deleting them programmatically through Microsoft Graph PowerShell.
Get-MgDirectoryDeletedItemAsGroup [-DirectoryObjectId <String>] [<CommonParameters>]
Parameters:
Below are practical examples of using the Get-MgDirectoryDeletedItemAsGroup cmdlet in Microsoft Graph PowerShell.
Get-MgDirectoryDeletedItemAsGroup
This command lists all the deleted Microsoft 365 groups currently stored in your organization’s recycle bin.
Get-MgDirectoryDeletedItemAsGroup -DirectoryObjectId 78db8584-3633-4c8a-ae6e-e144d63e7e12
This command retrieves details of a specific deleted group, using the provided Directory Object ID.
Note: The Group ID (DirectoryObjectId) is required when you want to restore or permanently delete a group programmatically using Graph PowerShell. You can only obtain this ID using the Get-MgDirectoryDeletedItemAsGroup cmdlet.
Get-MgDirectoryDeletedItemAsGroup | Select-Object Id, DisplayName, Description, DeletedDateTime
Get-MgDirectoryDeletedItemAsGroup | Export-Csv "DeletedGroups.csv" -NoTypeInformation
Here are some common scenarios where this cmdlet is useful:
Quickly identify and restore Microsoft 365 groups that were deleted unintentionally using:
Restore-MgDirectoryDeletedItem -DirectoryObjectId <GroupId>
Generate reports of deleted groups to analyze deletion patterns or ensure compliance.
Remove deleted groups that are no longer needed by combining with:
Remove-MgDirectoryDeletedItem -DirectoryObjectId <GroupId>
Use this cmdlet in automation workflows that detect and restore critical deleted groups based on predefined conditions.
| Error | Cause | Solution |
|---|---|---|
| Access Denied. You do not have the required permissions to access this resource. | The connected account doesn’t have sufficient permissions. | Reconnect using Connect-MgGraph -Scopes "Group.Read.All", "Directory.Read.All". |
| Resource not found for the segment 'directoryObjects'. | The specified group ID no longer exists or has already been permanently deleted. | Verify the ID using Get-MgDirectoryDeletedItemAsGroup before performing restore or delete actions. |
| Get-MgDirectoryDeletedItemAsGroup : The term is not recognized | The Microsoft Graph module is not installed or imported. | Install and import the module using: Install-Module Microsoft.Graph Import-Module Microsoft.Graph |
| Insufficient privileges to complete the operation | The app registration or user lacks admin consent for the required permissions. | Ensure that the app or user account has admin consent for Group.Read.All and Directory.Read.All scopes. |
The Get-MgDirectoryDeletedItemAsGroup cmdlet is an indispensable tool for managing deleted Microsoft 365 groups. It allows administrators to easily retrieve group details, audit deleted resources, and prepare for restoration or permanent deletion.
Remember, the Group ID retrieved through this cmdlet is required to restore or permanently delete groups programmatically via Microsoft Graph PowerShell.
By integrating this cmdlet into your daily administrative scripts, you can maintain tighter control over your Microsoft 365 environment and ensure no critical group is lost permanently by mistake.
© m365corner.com. All Rights Reserved. Design by HTML Codex