SharePoint 2013: Error Creating Publishing Sites with Powershell


Creating a Publishing site collection in SharePoint 2013 Preview using the Central Administration UI, results in a nice shiny publishing site, as you’d expect;

Publishing Site
Publishing Site

Creating the same site using Powershell, at least for me, resulted in something not quite the same.

Publishing Site via Powershell
Publishing Site via Powershell

The powershell I used was this, simple stuff;

## =====================================================================
## Title       : Add-SPSite
## Description : Adds a New SharePoint Site.
## Input       : Add-SPSite [[-url] <String>] [[-Title] <String>] [[-Description] <String>] [[-Template] <String>] [[-OwnerAlias] <String>]
## Output      : 
## Usage       : Add-SPSite -url http://sp/sites/mysite -Title "My New Site" -Description "Description of New Site" -Template "STS#0" -OwnerAlias "PDOGS\Administrator" or "i:0#.w|pdogs\administrator" 
## Change log  :
## =====================================================================

param (

   [string]$url = "$(Read-Host 'url [e.g. http://sp/sites/mysite]')", 
   [string]$Title = "$(Read-Host 'Title of New Site Collection [e.g. My New Site]')",
   [string]$Description = "$(Read-Host 'New Site Collection Description [e.g. Description of My New Site]')",
   [string]$Template = "$(Read-Host 'Template to use [e.g. STS#0]')",
   [string]$OwnerAlias = "$(Read-Host 'Owner [e.g. PDOGS\Administrator or i:0#.w|pdogs\administrator]')"
)

function main() {

    Write-Host
    $site = Get-SPSite -Identity $url -ErrorAction SilentlyContinue
    if ($site -ne $null) {
        Write-Host "A site at ""$url"" already exists!" -ForegroundColor Red
        return
    }
    New-SPSite -url $url -OwnerAlias $OwnerAlias -Description $Description -Language 1033 -Name $Title -Template $Template
    Write-Host "Created new site at ""$url"" " -ForegroundColor White
}

Write-Host
$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.PowerShell'}
if ($snapin -eq $null) {
	Write-Host "    ..  Loading SharePoint PowerShell Snapin" -ForegroundColor Gray
    Add-PSSnapin -Name "Microsoft.SharePoint.PowerShell"
}
Write-Host "    Microsoft SharePoint PowerShell snapin loaded" -ForegroundColor Gray 

main

Checking the SPWeb properties of the root web didn’t yield much until I noticed that the MasterUrl and CustomMasterUrl properties were set to use the v4.master masterpage;

The fix was therefore easy, setting the MasterUrl and CustomMasterUrl properties using powershell to the new 2013 v15.master.

Clear-Host
$w = Get-SPWeb "http://sp/sites/ctype"
$w.MasterUrl = "/sites/ctype/_catalogs/masterpage/v15.master"
$w.CustomMasterUrl = "/sites/ctype/_catalogs/masterpage/v15.master"
$w.Update()
$w | select Url,ClientTag,MasterUrl,CustomMasterUrl,UseV15Rendering

Once done, the publishing site rendered using the correct masterpage.

Fixed Publishing Site
Fixed Publishing Site

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

One thought on “SharePoint 2013: Error Creating Publishing Sites with Powershell

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s