I have created a new custom page layout with custom content type using SharePoint designer 2013 and downloaded a copy of it. Now I have to upload that to another environment using PowerShell.

The written PowerShell script, uploads the the file to master page gallery, but the content type associated with the file is not shown in master page gallery list page. I have to manually edit the properties such as content type and associated content type. Then it will be shown on the list page. Is there a specific way to upload a page layout into master page gallery?

Could you please help me.

  • 1
    Hi and welcome to SP.SE Sooraj. Could you edit your post and add the PowerShell Script you're using? This way it would be easier to answer your question. Thank you! – Benny Skogberg Mar 3 '15 at 9:20

You can choose from several sets of APIs to add/upload publishing page layout. Below is demonstrated how to add/upload publishing page layout via CSOM in PowerShell.

Option 1


Function Get-ClientContext([string]$Url,[string]$UserName,[string]$Password)
    $SecurePassword = $Password | ConvertTo-SecureString -AsPlainText -Force
    $context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
    $context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName, $SecurePassword)
    return $context

Function Deploy-PageLayout([Microsoft.SharePoint.Client.Web]$Web,[string]$FilePath,[string]$AssociatedContentTypeId)
     $pageLayoutContentTypeId = "0x01010007FF3E057FA8AB4AA42FCB67B453FFC100E214EEE741181F4E9F7ACC43278EE8110003D357F861E29844953D5CAA1D4D8A3B001EC1BD45392B7A458874C52A24C9F70B"
     $fileName = [System.IO.Path]::GetFileName($FilePath)

     $associatedContentType = $Web.AvailableContentTypes.GetById($AssociatedContentTypeId)
     $catalogList = $Web.GetCatalog([Microsoft.SharePoint.Client.ListTemplateType]::MasterPageCatalog)    

     $fileContent = [System.IO.File]::ReadAllBytes($FilePath)
     $fileInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
     $fileInfo.Content = $fileContent
     $fileInfo.Url = $catalogList.RootFolder.ServerRelativeUrl + "/" + $fileName
     $fileInfo.Overwrite = $true

     $file = $catalogList.RootFolder.Files.Add($fileInfo)

     $listItem = $file.ListItemAllFields
     #listItem["Title"] = title;
     #listItem["MasterPageDescription"] = description;
     $listItem["ContentTypeId"] = $pageLayoutContentTypeId
     $listItem["PublishingAssociatedContentType"] = [string]::Format(";#{0};#{1};#", $associatedContentType.Name, $associatedContentType.Id.StringValue)
     $listItem["UIVersion"] = [Convert]::ToString(15)


$UserName = "jdoe@contoso.onmicrosoft.com"
$Password = Read-Host -Prompt "Enter the password"    
$Url = "https://contoso.sharepoint.com/"

$WelcomePageContentTypeId = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF390064DEA0F50FC8C147B0B6EA0636C4A7D4"
$WelcomePageFilePath = "C:\Assets\ContosoBlankWebPartPage.aspx"

$context = Get-ClientContext -Url $Url -UserName $UserName -Password $Password
Deploy-PageLayout -Web $context.Web -FilePath $WelcomePageFilePath -AssociatedContentTypeId $WelcomePageContentTypeId

Option 2

You could utilize PowerShell cmdlets from PnP project, in particular Add-SPOPublishingPageLayout command.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.