Home > Environment, PowerShell, SharePoint > Forcefully delete site collection

Forcefully delete site collection

Today I found a site collection on a customer environment which gave a completely blank page when you opened it via a browser. It didn’t gave a 404 (Not Found) error, it was just a blank page. I decided to figure out what was happening and found that during the creation of the site collection, an IISRESET had taken place. Because of this, the site wasn’t completely provisioned. Well, if it wasn’t completely provisioned, I don’t need it… Nobody could have added content.

I found out that I couldn’t remove the site using Central Administration. When you navigate to the site collection using the “Delete a site collection” page, the details (right hand site of the page) where not loaded and you cannot select the site collection. So… I wanted to delete the site using PowerShell, but this gave me an error:

PS C:\Users\macaw> remove-spsite http://dms/case/P68430
Are you sure you want to perform this action?
Performing the operation “Remove-SPSite” on target “http://dms/case/P68430“.
[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “Y”): Y
remove-spsite : <nativehr>0x80070003</nativehr><nativestack></nativestack>
At line:1 char:1
+ remove-spsite http://dms/case/P68430
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Share…mdletRemoveSite:SPCmdletRemoveSite) [Remove-SPSite], DirectoryNotFoundException
+ FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletRemoveSite

Apparently, the normal remove-spsite cmdlet cannot delete a site collection which is not fully provisioned, and this cmdlet doesn’t have a force flag. To forcefully delete the site collection, I used the SPContentDatabase.ForceDeleteSite method:

$siteUrl =http://dms/case/P68430
$site = get-spsite $siteUrl
$siteId = $site.Id
$siteDatabase = $site.ContentDatabase
$siteDatabase.ForceDeleteSite($siteId, $false, $false)

  1. September 9, 2015 at 15:05

    Its works for me..thanks a lot for the solution

  2. November 10, 2015 at 04:04

    You saved my day….thanks a lot

  3. Prasad
    January 7, 2016 at 06:14

    Hi, I have same issue, attempted the above cmdlets and I still get an error msg ‘Failed to update database “xxxxx” because the database is read only.

    background info:

    1> the above was initiated as we have been observing critical level errors in the event log (event id 6398) with the message :”The Execute method of job definition Microsoft.SharePoint.Administration.SPAppInstallationJobDefinition (ID xxxxxxxxx) threw an exception. More information is included below.

    Failed to update database “xxxxxx” because the database is read-only.”

    2> We cannot see site collection details on the right in CA

    3> Checked DB on SQL server it is not in read only mode

    4> the site collection has got its own database
    5> I cannot view the site in the browser but is listed in CA as a site collection and also in the list of content DB’s

    any opinion to progress this to deletion

    thank you Prasad

  4. Chintan
    December 28, 2016 at 07:26

    Awesome solution.

  5. aZU
    June 24, 2017 at 12:48

    Thank You..

  6. October 5, 2017 at 13:09

    Thank you 🙂

  7. Anonymous
    November 8, 2017 at 11:37

    Doesn’t work. The site remains there.

  8. January 18, 2018 at 17:47

    We solved our problem with it, thanks

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Ben Prins

What I want to remember about SharePoint


my world of work and user experiences

Bram de Jager - Coder, Speaker, Author

Office 365, SharePoint and Azure

%d bloggers like this: