Applies To

  • SharePoint 2010
  • SharePoint 2013
  • SharePoint 2016

 


Scenario

You are trying to clean up the Content Databases and deleting all unused databases which are attached to SharePoint. Usually, you detach the Content DB from SharePoint and then delete it from SQL. But what if you forget to detach it from SharePoint but you removed it from SQL Server? Now you have all those sites showing in the Central admin but no properties for them.

OR

You are trying to create tons of site collections via a batch script and some sites collections failed to provision completely and become orphaned in the SharePoint.

 


Solutions

Solution # 1: Remove-SPSite

  • Try to run the following PowerShell command to remove them.
    Remove-SPSite -Identity "http://Sitecollection"
  • But this throws the below error:

    Remove-SPSite : <nativehr>0x80070003</nativehr><nativestack></nativestack>At line:1 char:14

 

Solution # 2: STSADM

  • Try to use Old Fashioned Stsadm command.

    stsadm -o deletesite -force -siteid e2a114b8-80c9-41f6-87bf-3feddf2ad9b6 -databaseserver DS1 -databasename DB1
  • Again, luck is not with us and failed with the same error mentioned above.

 

Solution # 3: Repair Content DB

  • Try to repair the Content DB.
    $db = Get-SPContentDatabase -Site "";
    $db.Repair($true);
    $db.Update();
  • Even this completed without any issue but bad sites are still showing.

 

Solution # 4: Delete SiteDatabase

  • Try to delete using SPContentaDatbase Force Method.
    $site = Get-SPSite "";
    $siteId = $site.Id;
    $siteDatabase = $site.ContentDatabase;
    $siteDatabase.ForceDeleteSite($siteId, $false, $false);
  • As soon as this script completed successfully, the orphan site is gone from Central Admin.

There is no guarantee that these methods will work in your situation, but all above list options which we are using in our farm for deleting orphaned stuff. In your case maybe #1 or #2 or maybe #4 works. But Solution #4 should work for everyone.