Recover Deleted Office 365 Groups using PowerShell

Microsoft using Office 365 Group as a base service for other products like Planner, MS Teams, Yammer, etc… , so keeping its identity is very important. You might have deleted an O365 group without knowing its usage in other services, in this case you will also loose the group’s dependent contents. If you soft-deleted the office 365 group, by default the deleted object retained for 30 days (retention period) and you can easily restore the group and its associated content within this retention period, after the retention period the group and its associated content will be permanently deleted and cannot be restored.

When a group is restored, the following group associated content also get recovered: Office 365 Group’s Azure AD object and its properties, group SMTP address, Exchange Online shared inbox and calendar, SharePoint Online team site and files, OneNote notebook, Planner buckets and tasks, Microsoft Teams and other associated contents.

We can recover deleted unified groups using Restore-AzureADMSDeletedDirectory cmdlet from Azure AD PowerShell V2 module. Before proceed install Azure Active Directory PowerShell for Graph and run the below command to connect Azure AD PowerShell module:

Connect-AzureAD

Recovering a deleted office 365 group includes following two steps:

Find Id of the deleted office 365 group

Actually we need to pass the object Id of a deleted group to Restore-AzureADMSDeletedDirectory cmdlet, so we need to first get the object id of the deleted group that we want to restore.

Get-AzureADMSDeletedGroup

The above command retrieves all the soft deleted groups in a directory that are recoverable. You can also filter the groups by name using the parameter -SearchString.

Get-AzureADMSDeletedGroup -SearchString "Test Group"

After running any one of the above two commands , note down the Id of the office 365 group that you want to restore.

Restore the deleted office 365 group

Once you got the Id of the deleted group from the above step, you can just run the following command after replacing the Id parameter with your target group object Id.

Restore-AzureADMSDeletedDirectoryObject –Id <deleted group id>

If you believe there is no duplicate entries in the deleted groups with the same name, you can use the following commands to get the deleted group Id and recover the object in single execution.

$groupId = (Get-AzureADMSDeletedGroup -SearchString "Test Group").Id
Restore-AzureADMSDeletedDirectoryObject –Id $groupId

Once you run the above command, the restoring process will be completed in few minutes. Run the following powershell command to verify that the group has been restored successfully.

Get-AzureADGroup -ObjectID $groupId
Advertisement

Leave a Comment