I have a problem on my SharePoint 2013 farm. I have a script to create web applications in my farm, but when I do I cant create publishing site collections within that web application. (Originally posted here: https://sharepoint.stackexchange.com/questions/64308/fails-to-create-publishing-site-collection-in-scripted-web-application
So, the environment is setup like this:
- We are using host headers for the applications.
- We have BackConnectionHostNames set up in registry.
- For now we use the Farm admin account to run the app pool.
- We have mysites setup and apparently working.
- No search is setup.
- We have a content type hub setup and apparently working.
So, the symptoms are appearing to me like this:
I cannot create publishing site collections in my new host header based web application when I created it from my script. When I go through the GUI to create the publishing site collection it says "working on it" for a while, then presents me with an error while still spinning the "working on it". In the event log there is this to read:
Event log message was: 'The site template was not provisioned successfully. Delete this site collection in Central Administration, and then create a new site collection.'. Exception was: 'Microsoft.SharePoint.SPException: Provisioning did not succeed. Details: Failed to initialize some site properties for Web at Url: '' OriginalException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)) ---> System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
If I created the web application from Central Admin GUI I can successfully create a Publishing Portal in it.
If I created the web application with my script I can create a team site successfully.
Below follows my script, can anyone see something that's apparently wrong with this? Did I forget something that the CA GUI takes care of?
$ver = $host | select version
if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"}
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Import-Module WebAdministration -ErrorAction SilentlyContinue
Function CreateWebApplication($WebApplicationURL, $HttpPort, $WebApplicationName,
$ContentDatabase, $ApplicationPoolDisplayName,
$ApplicationPoolIdentity, $ApplicationPoolPassword,
$PortalSuperReader, $PortalSuperUser) {
Write-Progress -Activity "Creating Web Application" -Status "Creating Web Application $WebapplicationURL"
if($WebApplicationURL.StartsWith("http://"))
{
$HostHeader = $WebApplicationURL.Substring(7)
$HTTPPort = "80"
}
elseif($WebApplicationURL.StartsWith("https://"))
{
$HostHeader = $WebApplicationURL.Substring(8)
$HTTPPort = "443"
}
$AppPoolManagedAccount = Get-SPManagedAccount $ApplicationPoolIdentity
$AuthenticationProvider = New-SPAuthenticationProvider –UseWindowsIntegratedAuthentication
#Create a new web application using the existing parameters, assign it to the WebApp variable such that object cache user accounts can be configured
$WebApp = New-SPWebApplication -ApplicationPool $ApplicationPoolDisplayName -ApplicationPoolAccount $AppPoolManagedAccount.Username -AuthenticationProvider $AuthenticationProvider -Name $WebApplicationName -url $WebApplicationURL -port $HTTPPort -DatabaseName $ContentDatabase -HostHeader $HostHeader
Write-Progress -Activity "Creating Web Application" -Status "Configuring Object Cache Accounts"
#Assign Object Cache Accounts
$WebApp.Properties["portalsuperuseraccount"] = $PortalSuperUser
$WebApp.Properties["portalsuperreaderaccount"] = $PortalSuperReader
Write-Progress -Activity "Creating Web Application" -Status "Creating Object Cache User Policies for Web Application"
#Create a New Policy for the Super User
$SuperUserPolicy = $WebApp.Policies.Add($PortalSuperUser, "Portal Super User Account")
#Assign Full Control To the Super User
$SuperUserPolicy.PolicyRoleBindings.Add(
$WebApp.PolicyRoles.GetSpecialRole(
[Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullControl))
#Create a New Policy for the Super Reader
$SuperReaderPolicy = $WebApp.Policies.Add($PortalSuperReader, "Portal Super Reader Account")
#ASsign Full Read to the Super Reader
$SuperReaderPolicy.PolicyRoleBindings.Add(
$WebApp.PolicyRoles.GetSpecialRole(
[Microsoft.SharePoint.Administration.SPPolicyRoleType]::FullRead))
Write-Progress -Activity "Creating Web Application" -Status "Updating Web Application Properties"
#Commit changes to the web application
$WebApp.update()
}
CreateWebApplication "http://add.ress.lan" 80 "Intranet 3"
"sp_intranet3_content" "Intranet3 Pool" "sp_farm" "P4sswd!"
"sp_superreader" "sp_superuser"