Requirement: Delete Office 365 Group using PowerShell
How to Delete an Office 365 Group?
As an admin, you can delete Office 365 groups through Microsoft 365 admin center.
- Log in to the Microsoft 365 Admin Center site: https://admin.microsoft.com
- Expand Groups and Click on Groups in the left navigation.
- Select the Office 365 group to delete.
- In the details pane, click on the “Delete” button and confirm the delete group in Office 365.
Delete Office 365 Group using PowerShell
To delete Office 365 group using PowerShell, use Remove-UnifiedGroup cmdlet. Here is an example:
#Get Credentials to connect $Credential = Get-Credential #Create the session $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ ` -Credential $Credential -Authentication Basic -AllowRedirection #Import the session Import-PSSession $Session -DisableNameChecking -AllowClobber #Delete the Office 365 Group Remove-UnifiedGroup -Identity "[email protected]" -confirm:$False #Remove the session Remove-PSSession $Session
Please note, the Identity parameter takes Name, Display Name, Alias, Email Address, GUID, etc. Also, the Remove-UnifiedGroup cmdlet prompts for delete confirmation. Here we’ve suppressed it with -Confirm:$False switch.
When you delete an Office 365 group, you are permanently removing all resources of the group, including mailbox conversations, SharePoint site, notebook, and Planner tasks. If you deleted the group by mistake, you have 30 days to recover it! Let’s see how to hard delete Office 365 group using PowerShell.
How to Permanently Delete Office 365 Group using PowerShell?
To hard delete Office 365 group using PowerShell, use the following steps:
Here is how to permanently remove Office 365 Group using PowerShell: Assuming you have Office 365 global admin permissions, Open Windows PowerShell as Administrator.
- Connect to Azure AD by typing Connect-AzureAD cmdlet. This opens the Sign-In page for azure AD. Enter your credentials and Sign-in.
- Retrieve deleted groups using: Get-AzureADMSDeletedGroup cmdlet. This returns all deleted groups with their IDs.
- Now, you can permanently remove the deleted group using the group ID. E.g Remove-AzureADMSDeletedDirectoryObject -id 22bdc734-251f-48db-8030-19eb5560ddc3