Tuesday, July 7, 2015

Deleting a Site Collection Forcefully

Before writing about the solution, let me brief the problem. I was working for one my clients, suddenly I got an error message inside the PowerShell window. I was trying to move a Site Collection using the Move-SPSite cmdlet to a new content database. "A transport-level error has occurred when receiving results from the server" was the error. This is not what I'm going to talk about as I'm still trying to rectify the cause for the same.

Just after the above error, the existing site collection stopped working. Once I select the Site Collection in the "View All Site Collections" in central admin, on the right side of the screen, all I saw was a empty values about the site collection. Even it was without a Content Database. My plan was to delete the site collection and restore the backup. But deleting failed due to the unavailability of the database. Even the Remove-Spsite cmdlet couldn't help me as it can only delete a full provisioned Site Collection. But the below approach worked well.

$siteUrl = “http://mydomain/Site“
$site = get-spsite $siteUrl
$siteId = $site.Id
$siteDatabase = $site.ContentDatabase
$siteDatabase.ForceDeleteSite($siteId, $false, $false)

Thanks to Peter.

No comments: