Today I stumbled upon a strange issue on a production SharePoint 2013 Farm.
I had a bunch of site collections created using a batch script, and one of those was unreachable.
It’s quite common (well, at least… it happens sometimes J) that a site creation process may fail, resulting in resources not provisioned correctly.
Since file provisioning is one of the last operation that is performed during site creation, you may get a 404 accessing the site home page.
But this was not the case. I got a 400 response (i.e. Bad Request). I could not even navigate to application pages (which are not “provisioned” as ghosted resources).
The symptoms of something gone wrong were quite evident in several places.
The Central Administration displayed the site in the sites list, but without any reference to the Content Database where it should have been created. No way to remove it using the web interface (all pages displaying information about the site had no content at all).
Ok, let’s clean it up and remove via script.
A simple Get-SPSite returned a valid object. But a subsequent Remove-SPSite failed with the dreaded “Unknown SPRequest error.occurred”.
I had not time to investigate, so I had to find a quick solution, sort of a “force delete” where the site cannot be deleted.
Therefore I used a not-so-well-know operation on the Content Database object: Microsoft.SharePoint.Administration.SPContentDatabase::ForceDeleteSite (see http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.administration.spcontentdatabase.forcedeletesite.aspx).
The PowerShell code is definitely simple:
$site = Get-SPSite http://siteurl
$siteId = $site.Id
$siteDatabase = $site.ContentDatabase
$siteDatabase.ForceDeleteSite($siteId, $false, $false)
As the documentation clearly states:
This way I managed to remove the corrupt site collection (and recreate it again with the same command I had used for the batch script, which completed successfully).
Hope useful J