In short, Host-named site collections allows you to have unique URL addresses for each site collection. Say for e.g. Instead of having a typical "Sales" site URL as: http://SharePoint.yourcompany.com/sites/sales, You can have it as http://sales.yourcompany.com and for HR, it can be http://hr.yourcompany.com and so on. As per Technet, HNSC as the preferred method for deploying site collections in SharePoint 2013. So, lets see how to create host named site collection in SharePoint 2013 using PowerShell.
- All necessary DNS entries must be created prior creating HNSC (Which is obvious!) You can create a Foward lookup zone in DNS with wildcard entry pointing to the Load balancer or Web Server's IP.
- The web application that houses host named site collection will be created without any host headers and listening to the default port 80. So the "Default web site" of IIS must be deleted first! Also make sure no other web app is using that port without host headers. If this can't be done for any reason, You have to manually add the host header entries in the bindings in IIS on every WFE.
Create Host-Named Site Collections Step-by-Step:Step 1. Create hosting Web Application for Host Named site collections:
By default, the New-SPWebApplication cmdlet creates web application in windows classic mode authentication! make sure you are providing -AuthenticationProvider switch to make it on claims authentication mode.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue #Set variables for New web application creation $WebAppName = "HNSC Host Web Application" #Variables for new Application Pool $AppPoolName = "HNSC App Pool" #Get the existing Managed Account $AppPoolAccount = Get-SPManagedAccount "Crescent\SvcAppPool" #To utilize existing AppPool, Use: Get-SPServiceApplicationPool <AppPoolName> $ContentDatabase = "SP13_HNSC_Content" $AuthProvider = New-SPAuthenticationProvider –UseWindowsIntegratedAuthentication #Create the web application $WebApp = New-SPWebApplication -ApplicationPool $AppPoolName -ApplicationPoolAccount $AppPoolAccount -Name $WebAppName -Port 82 -AuthenticationProvider $AuthProvider -DatabaseName $ContentDatabase -path "C:\inetpub\wwwroot\wss\VirtualDirectories\HNSCHost" #-URL http://G1WFE01
Step 2. Create Blank Root Site collection without templates:
The root site collection should be created without assigning any template to it. So, it will be a empty-blank site.
$ServerName = "http://G1WFE01" New-SPSite -URL $ServerName -Name "HNSC Root" -OwnerAlias "Global\SvcOwner"The above two steps can be performed either by PowerShell or with Central Admin UI and they are one time activity. Once we have the host web application and blank root site collection ready, we can create any number of Host header site collections in it.
Step 3. Create Host Named Site collection using PowerShell
SharePoint 2013 host named site collections can be created using PowerShell only. Here is the PowerShell script to create Host-named site collection:
$HostURL = "http://WFE01" $OwnerID = "Crescent\Support" $OwnerMail= "Support@Crescent.com" $SiteURL = "http://sales.crescent.com" $TemplateVal ="sts#0" #Team Site #Create the HNSC New-SPSite -url $SiteURL -HostHeaderWebApplication $HostURL -owneralias $OwnerID -owneremail $OwnerMail -Template $TemplateValThat's all! We are done! The above script creates a host named site collection of Team site template. Hit the URL in browser and you should be able to access the site now!!
Tail: Managed Paths in Host-Named site collections:
Unlike SharePoint 2010, SharePoint 2013 allows managed paths in host named site collections. Here is how: Create a new managed path "teams"
New-SPManagedPath "Teams" –HostheaderOnce the managed path is created, we can create site collection underneath as below:
$HostURL = "http://WFE01" $OwnerID = "Crescent\Salaudeen" $OwnerMail= "Support@Crescent.com" $SiteURL = "http://Sales.crescent.com/teams/cloud" $SiteName = "Clould Sales Team" $TemplateVal ="sts#0" #Get the Host named site collection by its name $webApp = Get-SPWebApplication $HostURL #Create new Host-named site under the managed path New-SPSite $SiteURL -OwnerAlias $OwnerID -HostHeaderWebApplication $webApp -Name $SiteName -Template $TemplateValNote that, there is no UI to create managed path for host named site collections, instead we have to use PowerShell cmdlet as above.
You might also like:
SharePoint Usage Reports
Usage reports, collaboration and audit for SharePoint.
Document SharePoint Farm
Automatically generate SharePoint documentation.