SharePoint Server: How to Delete a Site Collection Using PowerShell?

Requirement: Delete a SharePoint Site.

How to delete a site collection in SharePoint?

When you delete a site collection in SharePoint, all sites, including the top-level site and subsite underneath, and all data present in the site collection, all user information in the site collection gets deleted. To delete any SharePoint site collection, You can use either the SharePoint Central Administration site or PowerShell. In this post, we will walk through how to delete a site from SharePoint.

To delete a site collection in Central Administration, navigate to:

  1. SharePoint 2016 Central Administration >> Application Management.
  2. Click on Delete a site collection link under the Site Collections group.
    how to delete site collection powershell
  3. Select the site collection to delete
    delete site collection powershell sharepoint 2013
  4. Click on the Delete button to delete a site collection in SharePoint.
    powershell script to delete a site collection

Delete host-named site collection with PowerShell
Host-named site collections can be managed only through PowerShell! Central Admin doesn’t offer the provision to delete Host named site collections as it offers for Path-based sites. The following are some examples of deleting SharePoint 2013/2016 site collections using PowerShell.

Delete site collection through PowerShell

Deleting a site using PowerShell is a quick and easy way to remove unwanted content from your SharePoint environment without using the GUI. To delete site collection in SharePoint 2013 using PowerShell, use the Remove-SPSite cmdlet.

Remove-SPSite -Identity "<Site-Collection-URL>" 

E.g.

Remove-SPSite -Identity "https://sharepoint.crescent.com/sites/operations" 

Remove-SPSite cmdlet with -GradualDelete switch:

The -GradualDelete parameter instructs to delete the site collection gradually, instead of consuming all system resources to delete the site collection instantly in a single stretch. This reduces the load on the system when deleting large site collections.

Remove-SPSite -Identity "Site-collection-URL" -GradualDelete

Force delete SharePoint site collection with PowerShell

If you face any difficulty in deleting a SharePoint site collection either from Central Admin or with PowerShell, you can force delete site collection from the content database as:

#Get the site collection to delete
$Site = Get-SPSite https://site-collection-url

#Get the content database of the site collection
$SiteContentDB = $site.ContentDatabase 

#Force delete site collection
$SiteContentDB.ForceDeleteSite($Site.Id, $false, $false)

This deletes the orphaned site collection in SharePoint with PowerShell.

If you delete a site collection Remove-SPDeletedSite cmdlet or force delete a site collection with $GradualDelete parameter to $True, Then you’ll not be able to recover it using Restore-SPDeletedSite cmdlet! (You need content database backup instead!)

Bulk delete site collections with PowerShell in SharePoint

How about bulk deleting multiple site collections? Say, You want to delete all site collections under the given managed path: /Sites?

Get-SPSite "https://sharepoint.crescent.com/sites*" -Limit ALL | Remove-SPSite -Confirm:$false

PowerShell to delete all site collections under a web application:

If you don’t want to send your SharePoint sites to the recycle bin and would like to remove them permanently, use:

#Web Application URL
$WebAppURL="https://SharePoint.crescent.com"

#Get Each site collection and delete
Get-SPWebApplication $WebAppURL | Get-SPSite -Limit ALL | Remove-SPSite -Confirm:$false

Related posts:

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

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