SharePoint Online: Delete a Site Collection using PowerShell

Requirement: Delete a SharePoint Online Site Collection using PowerShell.

How to Delete a Site Collection in SharePoint Online?

SharePoint Online site collection is a collection of one or more sites that are grouped under the common URL and typically share a common navigation, branding, features, security, etc. When it comes to managing content in SharePoint Online, you may at some point need to delete a site when you no longer need it. E.g., Project completed, a Temporary site, or maybe it was created by mistake. Whatever the reason, you can delete it to free up storage space.

As a SharePoint Online Site Admin, you can delete any site in the tenant. This article will walk you through the process of deleting your site entirety, which includes all data, lists, libraries, and files associated with it. Before you begin this process, it’s a good idea to make sure that the site is no longer required. Deleting a site collection is a quite straightforward process. To delete a SharePoint Online site collection from the Admin center, follow the below steps:

  • Login to your SharePoint Online Admin Center (Typically at
  • Click on Sites >> Active Sites in the left navigation. From the site collections list, select the site collection to delete. From the Toolbar, click on “Delete” and then confirm by a prompt by clicking the “Delete” button.
    delete sharepoint online site using powershell

If you selected an Office 365 group connected site, you’d get a prompt with an option to delete the associated Office 365 group as well. Deleted sites are retained for 93 days in SharePoint Online, and then they will be permanently deleted. However, the deleted Office 365 groups are retained for only 30 days in Azure AD Recycle Bin.

If you have site collection Admin rights, You can also delete a site collection by directly going to the site >> Click on Settings >> Site Information >> Click on the “Delete Site” link!

how to delete a site in sharepoint online

This deletes all content associated with that particular SharePoint Online site within a few minutes, depending on how much data is deleted.

Delete Multiple Site Collections in SharePoint Online

Similarly, You can delete multiple SharePoint Online sites using the modern admin center by selecting more than one site collection >> Click on “Bulk Edit” >> Choose the “Delete” item in the menu and confirm the prompt!

delete multiple site collections in sharepoint online

Once deleted, You can find them under the “Deleted sites” link from the SharePoint Online admin center’s left navigation. Now, let’s delete a site collection in SharePoint Online with PowerShell!

How to Delete a SharePoint Online Site Collection using PowerShell?

Here is the PowerShell script for SharePoint Online to delete site collection. Use SharePoint Online Management Shell or PowerShell ISE to run these cmdlets.

Import-Module Microsoft.Online.Sharepoint.PowerShell

#Variables for processing
$AdminSiteURL = ""
$AdminName = "[email protected]"
$SiteCollURL = ""

#Credentials to connect 
$SecurePWD = ConvertTo-SecureString "Password" -asplaintext -force  
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $AdminName, $SecurePWD
#Connect to SharePoint Online
Connect-SPOService -url $AdminSiteURL -credential $Credential

#delete sharepoint online site collection using powershell
Remove-SPOSite -Identity $SiteCollURL -NoWait -Confirm:$false

Write-Host "Site collection has been deleted!"

SharePoint Online: Remove Site Collection with PowerShell

You can also use SharePoint Online Management Shell to delete site collection:

$AdminSiteURL = ""
$SiteCollURL = ""

#Connect to sharepoint online
Connect-SPOService -url "" -credential (Get-Credential)

#sharepoint online powershell delete site collection
Remove-SPOSite -Identity $SiteCollURL -NoWait -Confirm:$false

This PowerShell deletes site collection in SharePoint Online. Please note, The Remove-SPOSite does not delete a site collection permanently. But it moves the site collection to the Recycle Bin.

Remove Site Collection using PowerShell CSOM

When you delete a SharePoint Online site, all subsites, pages, lists and libraries, and content within site are also deleted. Here is how to delete a site with a client-side object model PowerShell script:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"

#delete site collection sharepoint online powershell
Function Remove-SPOSiteCollection($AdminCenterURL,$SiteURL)
    Try {
        #Setup Credentials to connect
        $Cred= Get-Credential
        #Setup the Context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminCenterURL)
        $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
        #Get the tenant object 
        $Tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Ctx)

        Write-Host -f Yellow "Deleting site collection..." 
        #delete a sharepoint online site powershell
        $Tenant.RemoveSite($SiteURL) | Out-null
        #$Tenant.RemoveDeletedSite($SiteURL) #To delete site from recycle bin!
        Write-host "Site Collection Deleted Successfully!" -foregroundcolor Green
    catch {
        write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
#Set Parameters
$AdminCenterURL = ""
$SiteURL = ""

#Call the function to delete site collection
Remove-SPOSiteCollection $AdminCenterURL $SiteURL
Permissions to Delete a Site in SharePoint Online
To delete a SharePoint Online Site Collection, You need to be a Site Collection Administrator / SharePoint Online Admin / Global Admin!

Permanently Delete the SharePoint Online Site Collection:

When you delete a site collection, it goes to the recycle bin. You may want to permanently delete that site collection to reuse the storage space or recreate a new site collection with the same URL. Because, If you try to create a site collection with a deleted site in the recycle bin, SharePoint gives you a message “The site address is available with modification” and doesn’t allow you to use the same URL!

powershell to delete sharepoint online site collection

How to Permanently Delete a Site Collection in SharePoint Online?

To delete a site collection permanently in SharePoint Online, Login to the new admin center site >> Click on “Deleted Sites” from left navigation. This lists all deleted sites in the tenant within the past 93 days. Select the site to delete and click on the “Permanently Delete” button in the toolbar and confirm the prompt.

sharepoint online permanently delete site collection powershell

However, if you try to delete a modern Office 365 group site permanently using the above steps, You’ll find the Permanently delete button is disabled! So the only way to permanently remove deleted Modern sites is: PowerShell! Let’s delete a site collection in SharePoint Online using PowerShell:

SharePoint Online PowerShell to Delete Site Collection Permanently from Recycle bin

We can use PowerShell to remove a deleted site in SharePoint Online. To permanently delete site collection from recycle bin, use the below script in SharePoint Online Management Shell: 

$DeletedSiteCollURL = ""

#Remove Deleted SharePoint Online Site Collection permanently
Remove-SPODeletedSite -identity $DeletedSiteCollURL -Confirm:$false

This deletes the site from the recycle bin.

SharePoint Online PnP PowerShell to Delete Site Collection

Here is how to delete a site collection in SharePoint Online using PnP PowerShell

#Config Variables
$SiteURL = ""

#Get Credentials to connect
$Cred = Get-Credential

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
#sharepoint online delete site collection powershell
Remove-PnPTenantSite -Url $SiteURL -Force 

To permanently delete site collection with PnP PowerShell, use the -SkipRecycleBin switch.

Remove-PnPTenantSite -Url $SiteURL -Force -SkipRecycleBin

To remove a deleted site collection from recycle bin with PnP PowerShell, use:

Remove-PnPTenantSite -Url $SiteURL -FromRecycleBin 

Removing stale content not only helps us to reduce storage costs but also helps users to find the right content they’re looking for more quickly – as we remove unnecessary sites.

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!

2 thoughts on “SharePoint Online: Delete a Site Collection using PowerShell

  • Do I need Tenant admin roles to delete a site collection?

    • Site collection Administrators can delete a site from site settings page or with PnP PowerShell. However for SharePoint Online Admin Center or SPO cmdlets, You need to have “SharePoint Online Administrator” permission.


Leave a Reply