How to Change Page layout of publishing pages in Sharepoint 2013 using powershell?

Hello Sharepointers,

Below are the powershell script to update the pagelayout of all the publishing page in a sharepoint site collection.

$spWeb = Get-SPWeb(“http://yoursitecollection/yoursite”)
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($spWeb)
$pSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($spWeb.Site);

$siteLayouts = $pSite.GetPageLayouts($false)
$myLayout = $siteLayouts[“/_catalogs/masterpage/custompagelayout.aspx”]
$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = “Scope=’RecursiveAll'”

$pages = $pWeb.GetPublishingPages($query)

foreach ($page in $pages)
if ($page.ContentType.Name -eq “Folder”)

$page.Layout = $myLayout

Hope it helps you guys. Happy SharePointing folks 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *