Creating site collections using SharePoint management shell 2013

sharepointvirtual-machines

I am creating Site Collections for Testing SharePoint. I am using Host Named Site Collection to do that instead of the path based site collection addressing.

For that

  1. Got a reference to the HNSC web application which I created before using web application management.

  2. created a non-templated site at the root of the web applications for workflow to connect.

    New-SPSite -Name "Root HNSC Site Collection" -Url "http://vspserver -HostHeaderWebApplication $hnscWebApp -OwnerAlias "vspserver \Administrator"
    
  3. but when I try to create a Team site by using the following scrpit:

    New-SPSite -Name "VSPServer Intranet" -Url "http://intranet.vspserver" –HostHeaderWebApplication $hnscWebApp -Template "STS#0" -OwnerAlias "vspserver\Administrator"
    

I get this error message:

New-SPSite : Cannot find an SPWebApplication object that contains the
following Name, Id, or Url: http://intranet.vspserver.test-lab.local.
At line:1 char:1
+ New-SPSite -Name "SPServer Intranet" -Url
"http://intranet.vspserver.test-lab.lo ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~
    + CategoryInfo          : InvalidData: (Microsoft.Share...SPCmdletNewSite:
   SPCmdletNewSite) [New-SPSite], SPCmdletPipeBindException
    + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletNewSite

Any idea would be appreciated.

Best Answer

You need to create a web app (SPWebApplication) that matches that subdomain first, and you need to refer to the new site collection with it's full FQDN, i.e.

http://intranet.vspserver.test-lab.local.

intranet.vspserver is not a FQDN, so it can't be used in a URL.