How to Restore a Microsoft Office 365 deleted Team using Powershell
Table of Contents
In Microsoft Teams, owners can delete the Team anytime, and it’s mostly for getting rid of the information which is not in use anymore, but sometimes it could also happen accidentally. Once the Team is deleted, its held in the recycle bin for 30 days before its permanently deleted, and no one can restore it anymore.
Before we start restoring the deleted Office 365 Team, some prerequisites need to be met. One of the requirements is your account needs to be a member of the Administrator group, and the AzureADPreview Powershell module needs to be installed.
Install AzureADPreview Powershell Module
You can also install the AzureADPreview by running the Powershell as administrator and executing the following command.
Once the AzureADPreview Powershell module is installed, it’s time to restore our Office 365 deleted Team. Let’s follow all the steps mentioned below and get our deleted Team fixed.
Connecting To AzureAD
You can connect to Azure Ad by running the following command in Powershell.
Connect-AzureAD
After running above Powershell command, a sign-in page will be prompted as shown below.
Enter your Office 365 Administrator credentials and click Sign in to continue. If your log in was successful you will get the following result.
Display all the deleted Microsoft Office365 Teams
In order to display all the deleted Microsoft Office 365 Teams, enter the following Powershell command.
Get-AzureADMSDeletedGroup
If your deleted list is very long, you can use -All $True at the end of the command.
Get-AzureADMSDeletedGroup -All $True
Now our next task is to find the Team which we need to restore. If you have a small number of deleted Teams, then there is no issue for you, but if the list is very lengthy below, the Powershell command will help you to find the desired Team very quickly.
Filtering the result using Powershell
In the below Powershell command, we are filtering the deleted office 365 Teams result and finding a Team that contains the word “Finance” in it. You can change it as your liking to find the desired Team quickly by filtering the result using Powershell.
Get-AzureADMSDeletedGroup -All $True | where {$_.DisplayName -like "*Finance*"}
Getting and saving the Object Id
Once the deleted Microsoft Office 365 Team is selected, its time to copy its group id by running the following command.
$Objectid = (Get-AzureADMSDeletedGroup -All $True | where {$_.DisplayName -like "*Finance*"}).ObjectId
After running the above Powershell command, the ObjectId of the selected deleted Team will be copied to a Powershell variable called \$ObjectId. We will use this Powershell variable to restore our deleted Team in the next step.
Restoring the Deleted Office 365 Team
Once the group id is copied in a variable, its time to restore the Team by running the following command.
Restore-AzureADMSDeletedDirectoryObject -Id $ObjectId
After successfully restoring the deleted Microsoft Office 365 Team, its time to verify it by running the following command.
Get-AzureADGroup -ObjectId $ObjectId
If everything went smoothly, you would get the following result after running the verify command.
You might also be interested in the following:
How To Bulk Create Teams & Channels using CSV & Powershell
How to Restore a Microsoft Office 365 deleted Team using Powershell