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:

  1. Log in to the Microsoft 365 Admin Center site in the web browser at: https://admin.microsoft.com
  2. Expand “Teams & Groups” and Click on Active Teams & Groups in the left navigation. 
  3. Select the Office 365 group to delete, which is no longer needed. 
  4. In the details pane, click on the “Delete” button at the top of the page and confirm the delete group in Office 365.
    how to delete office 365 group

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.

delete microsoft 365 group

Once a group is deleted, it goes to the recycle bin and stays for 30 days before they get deleted permanently.

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 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 "[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.

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 = "[email protected]"

#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 = "[email protected]"

#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:

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

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

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?

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

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

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

    Reply
    • 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.

      Reply
  • helped me too, thanks 🙂

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

    Reply

Leave a Reply

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