Microsoft Office 365Microsoft TeamsPowershell

How to Restore a Microsoft Office 365 deleted Team using Powershell

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.

Install-Module AzureADPreview

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.

sing-in

Enter your Office 365 Administrator credentials and click Sign in to continue. If your log in was successful you will get the following result.

connect-azuread

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
Get-AzureADMSDeletedGroup

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.

Recommended For You:  Run Linux Virtual Machines on Hyper-V: A Comprehensive PowerShell Guide
Get-AzureADMSDeletedGroup -All $True | where {$_.DisplayName -like "*Finance*"}
filter-deleted groups

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
Save-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
restore-deletedTeam

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.

verify-deletedTeam

Muhammad Faizan

Hi, My name is Muhammad Faizan and i have spent last 15 years working as System Administrator mainly with Microsoft Technologies. I am MCSE, MCTP, MCITP, certified professional. I love scripting and Powershell is the scripting language i am in love with.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button