Showing posts with label Host named site collections. Show all posts
Showing posts with label Host named site collections. Show all posts

Wednesday, March 11, 2015

Create explicit managed path for host named site collection using PowerShell commands

In SharePoint 2013, host-named site collections (HNSC) are all the rage. Host-named site collections give you the ability to provide completely different URLs for a site collection regardless of the web application URL hosting it.  For example, you might have a web application URL named http://sharepoint.mycompany.com and under it you have a collaboration site with a URL of http://collaborate.mycompany.com and an Intranet site namedhttp://intranet.mycompany.com.  This allows you to host multiple types of SharePoint sites together on a single web application which ultimately reduces the amount of resources your server farm needs for application pools.

Just like any site collection, you have to create a managed path for the URL you want.  We do this using New-SPManagedPath.  We can add explicit or wildcard inclusions just like you can for path-based site collections.  Wildcard is the default, if you want explicit, include the –explicit parameter.  We also need to add the –HostHeader parameter to indicate this is used with host-named site collections.  Here’s an example, where I created the business-solutions explicit path from our example above.

New-SPManagedPath "managed path name" -HostHeader –Explicit

This technically makes this managed path available on any host-named site collection.  If you want to see what managed paths have been created for host-named site collections, use Get-SPManagedPath with the –HostHeader command.

Get-SPManagedPath –HostHeader

Now, we need to create the site collection using New-SPSite.  It takes a few parameters but the important ones for this scenario is the URL we want for the new site collection and then –HostHeaderWebApplication to specify which web application hosts the new site collection.

New-SPSite “Site collection URL” –HostHeaderWebApplication “host web app URL” -Name "Site collection name" -OwnerAlias domain\user  -Template STS#0