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:
- Central Administration >> Application Management >> Delete Site Collection.
- Select the site collection from the drop-down and hit the “Delete” button.
- Confirm the prompt once to delete the host named site collection.
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
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'
}
else
{
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?