As promised I will hand out all the scripts I used in my SharePoint Conference 2014 sessions. The first set of scripts are from the demo used in the Real-world SharePoint Architecture decisions session (SPC334). This session only contained one demo in which I showed how to set up a Single Content Web Application and using Host Named Site Collections when creating Site Collections.

Creating the Web Application and the Root Site Collection

The first part of the script was to create the Web Application using SSL, configure the certificate in IIS and then create the Root Site Collection. The Web Application is created using the –Url parameter pointing to a FQDN, instead of using the server name (which is used in the TechNet documentation, and causes a dependency on that specific first server). Secondly the script assumes that the correct certificate is installed on the machine and we grab that certificate using the friendly name (yes, always have a friendly name on your certificates, it will make everything much easier for you). A new binding is then created in IIS using the certificate. Finally the Root Site Collection is created (it is a support requirement) – the Root Site Collection uses the same URL as the Web Application and we should not specify any template or anything. This will be a site collection that no end-user should ever use.

asnp *sh*

# New Web Application 
$wa = New-SPWebApplication `
    -Url 'https://root.spc.corp.local/' `
    -SecureSocketsLayer `
    -Port 443 `
    -ApplicationPool 'Content Applications' `
    -ApplicationPoolAccount 'CORP\spcontent' `
    -Name "SP2013SPC Hosting Web App " `
    -AuthenticationProvider (New-SPAuthenticationProvider) `
    -DatabaseName 'SP2013SPC_WSS_Content_Hosting_1' `
    -DatabaseServer 'SharePointSql'

# Get Certificate
$certificate = Get-ChildItem cert:\LocalMachine\MY | 
    Where-Object {$_.FriendlyName -eq "spc.corp.local"} | 
    Select-Object -First 1
$certificate.DnsNameList | ft Unicode

# Add IIS Binding
Import-Module WebAdministration
$binding = "IIS:\SslBindings\!443"
Get-Item $binding -ea 0 
$certificate | New-Item $binding

# Root site
New-SPSite `
    -Url https://root.spc.corp.local `
    -OwnerAlias CORP\spinstall

Creating Host Named Site Collections

Secondly we created a Host Named Site Collection (HNSC) in our Web Application. For HNSC this can only be done in PowerShell, and not in Central Administration, and we MUST use the –HostHeaderWebApplication parameter and it MUST have the value of the Web Application URL.

New-SPSite `
    -Url https://teams.spc.corp.local `
    -Template STS#0 `
    -OwnerAlias CORP\Administrator `
    -HostHeaderWebApplication https://root.spc.corp.local

My Site host and Personal Sites

If you would like to have Personal Sites and the My Site Host in the same Web Application (which in many cases are a good approach) then you must make sure to have Self Service Site Creation enabled on the Web Application and then use the following scripts. The script will first create a Farm level Managed Path for the Web Application by using the –HostHeader parameter. Then we just create the My Site Host as a Host Named Site Collection.

# Personal Sites
New-SPManagedPath `
    -RelativeUrl 'Personal' `

# My Site Host
New-SPSite `
    -Url https://my.spc.corp.local `
    -Template SPSMSITEHOST#0 `
    -OwnerAlias CORP\Administrator `
    -HostHeaderWebApplication https://root.spc.corp.local

In the session I also explained why you should have a dedicated Content Source for People Search (watch the session for more info). And using the following script we add the correct start addresses to the two content sources, based on the Site Collections created above:

# Configure Search
$ssa = Get-SPEnterpriseSearchServiceApplication

# The root web application
$cs = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $ssa -Identity "Local SharePoint sites"

# People search
$cs = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $ssa -Identity "Local People Results"

Once this is done, you just kick off a full crawl of the People Search and then wait for a couple of hours (so the Analytics engine does its job) before you start the crawl of the content.


This was all the scripts I used during the demo in the SPC334 session. It’s a proven method and I hope you can incorporate them into your deployment scripts.