2

I am trying to create a web application "http://Intranet" and a site collection "http://Intranet" on SharePoint 2013 foundation farm. Here is my code

$sp = New-SPAuthenticationProvider
$web = New-SPWebApplication -Name "Intranet Home" `
                 -Port 80 `
                 -Url "http://Intranet" `
                 -ApplicationPool "Intranet App Pool" `
                 -ApplicationPoolAccount (Get-SPManagedAccount "mars\svc_intranetapppool") `
                 -AuthenticationProvider $sp

$web = Get-SPWebApplication "http://Intranet"
# Create a New Site at the Base of the Web App
New-SPSite "http://Intranet"  -OwnerAlias "mars\aaronp" `
                        -Name "Intranet Sites" `
                        -HostHeaderWebApplication $web `
                        -Template "STS#0"

The error I get is

New-SPSite : The URL "http://Intranet" is in use as an alternate access URL or as the URL of a host header site.  
Please choose a different URL and try again.
At line:3 char:1
   + New-SPSite http://Intranet  -OwnerAlias "mars\aaronp" `
   + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   + CategoryInfo          : InvalidData: (Microsoft.Share...SPCmdletNewSite:SPCmdletNewSite) [New-SPSite], ArgumentException
   + FullyQualifiedErrorId : Microsoft.SharePoint.PowerShell.SPCmdletNewSite

How does one create a site collection at the root of the web-app.

3 Answers 3

3

If you want to create a Root Site Collection a the top level of your Web application you should not use the parameter: -HostHeaderWebApplication in the New-SPSite command.

This site collection must have the same URL as the Web application. Currently, SharePoint prevents the creation of a host-named site collection with the same URL as a Web application.

Therefore, the root site collection is created as a path-based site collection: "/"

#The last line from the code written by Joesoc above should be:
New-SPSite "http://Intranet" -OwnerAlias "mars\aaronp" -Name "Intranet Sites" -Template "STS#0"

#Without "-HostHeaderWebApplication $web `"
1
  • This worked for me. Thumbs up! Commented Jun 21, 2017 at 13:46
2

Sounds like you already have a site named that, or an Alternate Access Mapping that points to that URL.

Try and type

Get-SPSite -Limit All 

in a PowerShell session and look for a site called http://Intranet

If the URL does not show up, try checking for AAA's:

Get-SPAlternateURL

to see if you have defined the URL there

0
# SharePoint cmdlets
Add-PsSnapin Microsoft.SharePoint.PowerShell
# Set variables
$WebAppName = "Contoso Sharepoint1"
$WebAppHostHeader = "sharepoint1.contoso.com"
$WebAppPort = 80
$WebAppAppPool = "SharePoint1AppPool"
# This User has to be a Sharepoint Manager Account
$WebAppAppPoolAccount = "contoso\sp_serviceuser"
$WebAppDatabaseName = "Sharepoint1"
$WebAppDatabaseServer = "SQLServer\InstanceName"
$SiteCollectionName = "Homepage"
$SiteCollectionURL = ("http://" + $WebAppHostHeader)
$SiteCollectionTemplate = "STS#0"
$SiteCollectionLanguage = 1033
$SiteCollectionOwner = "contoso\UserName"

# Create a new Sharepoint WebApplication
New-SPWebApplication -Name $WebAppName -Port $WebAppPort -HostHeader $WebAppHostHeader -URL ("http://" + $WebAppHostHeader) -ApplicationPool $WebAppAppPool -ApplicationPoolAccount (Get-SPManagedAccount $WebAppAppPoolAccount) -DatabaseName $WebAppDatabaseName -DatabaseServer $WebAppDatabaseServer

# Create a new Sharepoint Site Collection
New-SPSite -URL $SiteCollectionURL -OwnerAlias $SiteCollectionOwner -Language $SiteCollectionLanguage -Template $SiteCollectionTemplate -Name $SiteCollectionName`enter code here`

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.