Force Delete Corrupted Site Collections in SharePoint using PowerShell
There is a strange issue in SharePoint 2013 environment today! One of the site collection provisioned via custom code is unreachable with a “404 page not found” error. However, the particular site is listed under central administration >> View all site collections! But no further details such as the content database, etc., are available for the site collection in Central Administration.
We concluded that the site collection is “Corrupted!”. There are many scenarios where a site may go corrupted, such as: Storage media failure, network connectivity issues, incorrect usage of PowerShell cmdlets (E.g., If you use Copy-SPSite without the “DestinationDatabase” parameter, You’ll end up in a corrupted site!), etc.
So, We tried deleting the site collection from SharePoint central admin, but SharePoint central administration didn’t let me select and delete the site. I tried STSADM -o DeleteSite and Remove-SPSite PowerShell cmdlet with no luck!
Stsadm and PowerShell ways resulted with an Error: <nativehr>0x80070003</nativehr><nativestack></nativestack>
Solution: How to Delete Corrupted Site Collections in SharePoint?
We can delete corrupt site collections with either STSADM or PowerShell in the below methods.
STSADM to delete corrupt site collection:
Step 1: We need the site ID, Database Server, Database name parameters of the site we need to delete. Run:
stsadm -o EnumAllWebs > SitesList.xml
This produces an XML file with details such as site collection IDs, content database, database server, etc., as below.
Step 2: Extract required parameter values and supply it to STSADM -o DeleteSite as:
stsadm -o deletesite -force -siteid “1252fd8f-a0ea-4ef9-9b66-4715f8e44b37” -databaseserver SP13-Ent-SQL01 -databasename SP13_Intranet_Content
The Same method applies to corrupted site (web) as well. E.g.:
stsadm -o deleteweb -force -webid <Web ID> -databasename <database name> -databaseserver <database server name>
Delete corrupt site collection with PowerShell:
Use this PowerShell script to delete a corrupted site collection in SharePoint.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$CorruptedSiteURL ="https://intranet.crescent.com/sites/sales"
#Get the site collection
$site = Get-SPSite $CorruptedSiteURL
#Get the GUID of the site collection
$siteGUID = $site.Id
Write-host "Site collection GUID:"$siteGUID
#Get the content Database of the Site collection
$siteDatabase = $site.ContentDatabase
#Force delete the site collection
$siteDatabase.ForceDeleteSite($siteGUID, $false, $false)
Hi Salauddeen,
Wonderful article!
I have one clarification, how we can delete the orphaned personal sites from SharePoint on-premise using Rest API?
Really Very Helpful. Thank you Salaudeen 🙂