How to Delete a Host Named Site Collection in SharePoint using PowerShell?

Requirement: Delete a host named site collection using PowerShell in SharePoint.

How to delete a host named Site Collection?

Host Named Site Collections (HNSC) are an alternative way of creating site collections in SharePoint that allows the use of unique domain names instead of relying on managed paths. Generally, Host named site collections in SharePoint are managed through PowerShell. Prior to SharePoint 2013, You couldn’t delete host-named site collections from the Central Administration site, as the delete button is greyed out on the delete site collection page. However, from SharePoint 2013, you can delete either host-named site collection or path-based site collection from:

  1. Central Administration >> Application Management >> Delete Site Collection.
  2. Select the site collection from the drop-down and hit the “Delete” button.
  3. Confirm the prompt once to delete the host named site collection.
    delete host named site collection powershell

Delete host named site collection using PowerShell:

To delete a Host named site collection using PowerShell, use Remove-SPSite cmdlet in SharePoint Management Shell.

Remove-SPSite -Identity "https://Host-Named-Site-Collection-URL"

This removes the given host named site collection. Be sure to replace the “https://Host-Named-Site-Collection-URL” with the URL of the Host Named Site Collection you want to delete.

Permanently remove the deleted site collection:

If you want to re-use the same URL or free-up disk space occupied by the deleted site collection, you must permanently delete the site collection with PowerShell. Use Remove-SPDeletedSite cmdlet to remove deleted site collections permanently. 

Get-SPDeletedSite | Remove-SPDeletedSite
sharepoint 2013 delete host named site collection

This removes the host-named site collection permanently.

Get All Host Named Site Collections:
To get all host named site collections in a SharePoint Web application, use this PowerShell script.

$webApp = Get-SPWebapplication "https://web-application-url"

foreach($Site in $WebApp.Sites)
   if ($Site.HostHeaderIsSiteName)
       Write-Host $Site.Url 'is host-named Site Collection' 
       Write-Host $Site.Url 'is path based Site Collection' 

Here is another post on deleting site collections in SharePoint How to Delete Site Collection using PowerShell in SharePoint?

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 *