Skip to content

How to quickly and properly delete a Team (without waiting)

Article update

2020-11-29 : I've updated the article following the update of the CLI for Microsoft 365, adding a new command for permanently delete a site collection.

Use Case

You work for a company that wants to automatically create a Team with Tabs, Channels and other stuff that will make a new project team ready to rock the stage.

You are preparing the process and for mastering it, you have create / test / destroy / retry. But when you want to clean up your mess, you have to know that, during 30 days:

  • Your Team still exists as a Group (you can find it in the "Deleted Groups" menu on AAD), same for the associated e-mail address
  • The Team Site also still exists

So let's says that you made a mistake during the creation of a Team and want to "start over" (with same name of course), if you don't want to wait for the Office 365 Job to update your environment and re-create the Team with same name:

  • The SharePoint Site URL takes a number at the end of its address (of course, because the older one's still here)

  • You can't permanently delete the Teams Site, as the SharePoint Admin Center detects that the related Group still exists

Here's a step by step process to delete quickly a Team ! I recommand to follow them in this order to make everything's work.

Prerequisites

  1. An Office 365 (Dev) Tenant or a Partner Demo Tenant
  2. An Account with the following Office 365 roles
    • SharePoint Admin
    • Teams Admin
  3. An Account with the following Azure AD role
    • Groups administrator
  4. Command Interface (one of these)

Delete Group

Delete Group with Interface

Throught the UI, you have to delete the Group then permanently delete it

alt text

alt text

Delete Group with code

1
2
3
Connect-AzureAD -TenantId "TenantId"
Remove-AzureADGroup -ObjectId "GroupId"
Remove-AzureADMSDeletedDirectoryObject -Id "GroupId"
1
2
3
# (As there's no CLI command to permanently delete a Group,
# you'll have to do it through the UI)
aad o365group remove --id "GroupId" --confirm

Delete Team (if necessary)

Sometimes, once a Group is permanently deleted, the Team still exists. If it's the case and once again, you don't want for the Job to delete it, you can do it yourself. But don't be surprise if the following commands throw an error : maybe the Job has already worked.

Delete Team with Interface

Throught the UI (if you have an owner account) or Admin Interface, you can delete the Team

alt text

OR

alt text

Delete Team with code

1
2
Connect-MicrosoftTeams -TenantId "TenantId"
Remove-Team -GroupId "GroupId"

Delete Site Collection

As I told you before (even if you did the previous steps), if you try to delete the Teams Site from the SharePoint Admin Center, you won't be able to remove it from the Site Collection Recycle Bin (because of the O365 Job Tenant update process).

Delete site with code

1
2
3
4
5
6
7
8
9
# If you are familiar with the Get-PnPStoredCredential cmdlet,
# you can use it here with the "-Credential" Argument
Connect-PnPOnline -TenantId "TenantId"

# Remove the site
Remove-PnPTenantSite -Url "TeamsSiteUrl" -Force -SkipRecycleBin

# Remove the site from the Site Collection Recycle Bin
Clear-PnPTenantRecycleBinItem -Url "TeamsSiteUrl" -Force -Wait
1
2
3
4
5
# Remove the site
spo site classic remove -u "TeamsSiteUrl" --skipRecycleBin --confirm --wait

# Remove the site from the Site Collection Recycle Bin
spo tenant recyclebinitem remove -u "TeamsSiteUrl" --confirm --wait

That's it

Et voilà ! You can start over your process until it's ready to use.

Of course, you could also make those tasks with the SharePoint Online Management Shell or with the Graph API, but here I've covered the most common ways of working with Teams / Group / SharePoint administration.