Oops…So I accidentally deleted a few O365 groups last week. Happens to everyone at some point right? Luckily, as long as it has been less that 30 days since you deleted it, you are in the clear and can restore it! Note: If you were a try hard and used Remove-MsolGroup to delete the group, you’re screwed. Full disclosure the very detailed walk through I followed can be found here, but I am going to do my own quick write up for future reference. With all that being said, strap in!
We need to start by installing the AzureADPreview PowerShell module. Yeah, it’s in preview (haha). So pop open a PowerShell window as administrator and run the following. If you have a previous version of the module you will need to uninstall it and install the most up to date version.
1 2 3 4 5 |
#Uninstall previously installed version Uninstall-Module AzureADPreview #Install up to date version Install-Module AzureADPreview |
Tough stuff. You may receive the following prompts to download the repository and that it is untrusted. Accept them, they’re not super hackers or anything.
1 2 3 4 5 6 7 8 9 10 11 12 |
#Add necessary provider prompt PowerShellGet requires NuGet provider version '2.8.5.201' or newer to interact with NuGet-based repositories. The NuGet provider must be available in 'C:\Program Files\PackageManagement\ProviderAssemblies' or 'C:\Users\scotts\AppData\Local\PackageManagement\ProviderAssemblies'. You can also install the NuGet provider by running 'Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force'. Do you want PowerShellGet to install and import the NuGet provider now? [Y] Yes [N] No [S] Suspend [?] Help (default is "Y"): Y #Untrusted repository prompt You are installing the modules from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the Set-PSRepository cmdlet. Are you sure you want to install the modules from 'PSGallery'? [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "N"): Y |
Now we are all prepped and ready to go. If you closed that PowerShell window get it open again as administrator. Run the following to restore your group (further instructions below).
1 2 3 4 5 6 7 8 9 10 11 12 |
#Import the module Import-Module AzureADPreview #Connect to Azure AD Connect-AzureAD #Insert O365 credentials as prompted for desired tenant. #List all deleted groups in past 30 days Get-AzureADMSDeletedGroup #Restore the deleted group Restore-AzureADMSDeletedDirectoryObject -Id <Paste Group ID Here> |
It’ll take a few seconds but you will now have your group restored and can go back to normal.