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: 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.
    how to delete office 365 group
You can also delete a Microsoft 365 Group from Azure AD! Login to Azure Active Directory >> Click on “Groups” >> Select the desired group and hit Delete button.

Delete Office 365 Group using PowerShell

To delete Office 365 group using PowerShell, use Remove-UnifiedGroup cmdlet. Here is an example:

#Connect to Exchange Online
Connect-ExchangeOnline -ShowBanner:$False

#Delete the Office 365 Group
Remove-UnifiedGroup -Identity "[email protected]" -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.

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:

Pr-requisites: You need to have the Azure Active Directory Module installed! You can check if you have Azure AD module 2.0 installed by Get-InstalledModule. If you have previous versions of the module installed, You may have to uninstall using “Uninstall-Module AzureAD” and then install the latest version using “Install-Module AzureAD” cmdlet.
#Parameters
$GroupEmail = "[email protected]"

#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!"
}

When you delete an Office 365 group, you permanently remove all group resources, 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.

  1. Connect to Azure AD by typing Connect-AzureAD cmdlet. This opens the Sign-In page for azure AD. Enter your credentials and Sign-in.
  2. Retrieve deleted groups using: Get-AzureADMSDeletedGroup cmdlet. This returns all deleted groups with their IDs.
  3. Now, you can permanently remove the deleted group using the group ID. E.g Remove-AzureADMSDeletedDirectoryObject -id 22bdc734-251f-48db-8030-19eb5560ddc3 
permanently delete office 365 group powershell

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

3 thoughts on “How to Delete an Office 365 Group using PowerShell?

  • Can you then restore the SharePoint site without the O365 group?

    Reply
  • helped me too, thanks 🙂

    Reply
  • excellent explanation. it helped me a lot!! thanks!!

    Reply

Leave a Reply