How to Delete an Office 365 Group using PowerShell?
Requirement: Delete Office 365 Group using PowerShell.
How to Delete an Office 365 Group?
Microsoft Office 365 Groups offer a collaborative environment for teamwork. However, sometimes you may need to delete an Office 365 Group. Perhaps, You may want to clean up old Office 365 groups. This blog post will walk through the steps necessary to delete an Office 365 Group using Microsoft Admin Center. We will also show you how to delete an Office 365 Group using PowerShell.
You can delete Office 365 groups through Microsoft 365 admin center as an admin. The process is as simple as just clicking a few buttons:
- Log in to the Microsoft 365 Admin Center site in the web browser at: https://admin.microsoft.com
- Expand “Teams & Groups” and Click on Active Teams & Groups in the left navigation.
- Select the Office 365 group to delete, which is no longer needed.
- In the details pane, click on the “Delete” button at the top of the page and confirm the delete group in Office 365.
You can also delete the Microsoft 365 group by selecting the check box next to the group and clicking on the “Delete team” button in the toolbar.
Once a group is deleted, it goes to the recycle bin and stays for 30 days before they get deleted permanently.
Delete Office 365 Group using PowerShell
To delete the Office 365 group from the Exchange Online PowerShell module, use the Remove-UnifiedGroup cmdlet. Here is an example:
#Connect to Exchange Online
Connect-ExchangeOnline -ShowBanner:$False
#Delete the Office 365 Group
Remove-UnifiedGroup -Identity "ConsumersGroup@TheCrescentTech.com" -confirm:$False
#Disconnect Exchange Online
Disconnect-ExchangeOnline -Confirm:$False
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.
Delete Microsoft 365 Group using PnP PowerShell
To delete a Microsoft 365 group, use this PnP PowerShell cmdlet Remove-PnPMicrosoft365Group
#Config Variables
$AdminSiteURL = "https://crescent-admin.sharepoint.com"
$GroupEmail = "RetailManagers@crescent.com"
#Connect to PnP Online
Connect-PnPOnline -Url $AdminSiteURL -Interactive
#Get the Group
$Group = Get-PnPMicrosoft365Group | Where Mail -eq $GroupEmail
If($Group -ne $null)
{
#Delete the Group
Remove-PnPMicrosoft365Group -Identity $Group.id
Write-host "Group Deleted Successfully!" -f Green
}
Else
{
Write-host "Could not find Group!" -f Yellow
}
How do I permanently delete a deleted group in Office 365?
Similarly, to permanently delete the group from your Microsoft 365 tenant, use the Remove-PnPDeletedMicrosoft365Group cmdlet:
#Config Variables
$AdminSiteURL = "https://crescent-admin.sharepoint.com"
$GroupEmail = "RetailManagers@crescent.com"
#Connect to PnP Online
Connect-PnPOnline -Url $AdminSiteURL -Interactive
#Get the deleted Office 365 Group
$Group = Get-PnPDeletedMicrosoft365Group | Where Mail -eq $GroupEmail
If($Group -ne $null)
{
#Delete the Group
Remove-PnPDeletedMicrosoft365Group -Identity $Group.id
Write-host "Group Deleted Permanently!" -f Green
}
Else
{
Write-host "Could not find deleted Group!" -f Yellow
}
This script purges the deleted group from the recycle bin.
Remove a Microsoft 365 Group using Azure AD PowerShell
This time, let’s remove a Microsoft 365 group by its Email ID with the help of the Azure Active Directory PowerShell module:
#Parameters
$GroupEmail = "Purchase@Crescent.com"
#Connect to AzureAD
Connect-AzureAD -Credential (Get-Credential) | Out-Null
#Get the Azure AD Group
$Group = Get-AzureADGroup -Filter "Mail eq '$GroupEmail'"
If($Group)
{
$Prompt = Read-Host "Are you sure want to delete the Group (Y/N)?"
If($Prompt -eq "Y")
{
#Delete the Office 365 Group
Remove-AzureADGroup -ObjectId $Group.ObjectId
Write-Host "Group Deleted Successfully!" -f Green
}
}
Else
{
Write-host -f Yellow "Could not find Group with Email $GroupEmail!"
}
What happens when an Office 365 group is deleted? When you delete an Office 365 group, you remove all group content, including mailbox, group conversations, associated SharePoint sites, group calendar, group notebook, Yammer, 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 Azure AD 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
How do I recover a deleted group? If you have deleted a Microsoft 365 group by mistake, IT Admin can restore it within 30 days! How to Recover a Deleted Office 365 Group?
Conclusion
In conclusion, deleting an Office 365 group can be done using either the Microsoft 365 admin center or PowerShell. The Microsoft 365 admin center provides a user-friendly interface for admins who are not comfortable using PowerShell, while PowerShell provides greater automation capabilities. Regardless of which method you choose, the process is straightforward and easy to follow. By removing unused or unnecessary Office 365 groups, you can streamline your environment and improve your organization’s productivity. It is important to note that deleting an Office 365 group will also delete any associated data, such as files, conversations, and events. Therefore, it is recommended that you carefully review the contents of the group before deleting it.
Thank you! I accidentally created the group with the wrong settings and deleted it but I could not create it again using the same name.
You got to permanently delete the soft-deleted group to re-use it’s name!
Can you then restore the SharePoint site without the O365 group?
When you delete a SharePoint Online site, its associated group and its associated resources also get deleted. Similarly, when you restore the site – its Office 365 group also gets restored.
helped me too, thanks 🙂
excellent explanation. it helped me a lot!! thanks!!