Script to Change Page Layout on Publishing Pages – PowerShell

If you want change pagelayouts, you can use this usefull script.

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

$siteLayouts = $pSite.GetPageLayouts($false)
$myLayout = $siteLayouts["/_catalogs/masterpage/fcPageLayout.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")
     {
         continue
     } 
     $page.Layout = $myLayout
     $page.update()
     $page.ListItem.File.Publish("")
     $page.ListItem.File.Approve("")
}
$spWeb.Dispose()
Advertisements

Posted on 14/05/2015, in PowerShell and tagged , , , , . Bookmark the permalink. Leave a comment.

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

%d bloggers like this: