Find and Delete Orphaned Site Collections in SharePoint

Orphaned Site Collection in SharePoint
Orphaned sites are broken sites created in situations like restore interrupt/failure. Often, sites without parent site reference, lists or libraries without site is referred as orphans in SharePoint. These objects are with broken relationship and should be deleted from SharePoint content databases prior to upgrade.

During a migration project, I had to clean the SharePoint sites before migration as the preupgradecheck reported a huge list of orphaned sites. remove Orphaned site collections in SharePoint

How to Delete Orphaned SharePoint Sites?

There are many ways to remove orphaned site collections in SharePoint. To remove orphaned site collections in SharePoint 2007 / SharePoint 2010 or in SharePoint 2013, use one of the following methods:

 1.  Detach the content DB and attach again

 2.  To detect orphaned items, use the following command line:
stsadm -o databaserepair -url https://Web-App-URL -databasename <database Name>

To delete orphaned items, use the following command line:
stsadm -o databaserepair -url https://Web-App-URL -databasename <database Name> -deletecorruption

3. Do STSADM -o EnumAllWebs, note down the Orphan site id’s, and then execute:  
    stsadm -o deletesite -force
   -siteid <site ID> (ID is listed in an output from enumallwebs)
   -databasename <database name>
   -databaseserver <database server name>

This will delete orphaned site collection in SharePoint.

4. PowerShell script to find and delete orphaned items in SharePoint:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$ContentDBColl = Get-SPContentDatabase

ForEach ($Database in $ContentDBColl)
{
   Write-Host "Detecting Orphans for " $Database.Name
   $Database.Repair($true)
}

In case, all the above fails, you can force delete site collection using PowerShell. Here is how: Force Delete Site Collections in SharePoint using PowerShell

Fix Orphaned Items in SharePoint 2013:
SharePoint 2013 comes with a health analyzer rule to detect and fix orphaned items. Head-on to SharePoint 2013 central administration >> Monitoring >> Click on “Review problems and solutions” under Health Analyzer >> pick “Content databases contain orphaned items.” from the list.

remove orphaned site from sharepoint 2013

Click on “Repair Automatically” to delete orphaned items.

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 *