SharePoint 2013 Change Page Layout using PowerShell

InfoPath alternatives for form designing SharePoint

In this post we will discuss how we can change page layout using PowerShell in SharePoint 2013. We can use PowerShell to change page layout in SharePoint 2013.

You can also read:
– Enable Breadcrumb in SharePoint 2013 or Implement Classic Breadcrumb in SharePoint 2013

– Get all workflows from all site collections using server object model in SharePoint 2013

– Custom Ribbon Action and set the Customize Icon to Ribbon button in a SharePoint Hosted App

Below is the PowerShell script to change page layout of default.aspx page in a SharePoint 2013 site or sub site.

Add-PSSnapin “Microsoft.SharePoint.PowerShell”
$spWeb = Get-SPWeb(“https://SiteURL”)

$spFile = $spWeb.GetFile(“https://SiteURL/Pages/default.aspx”)
$spFile.CheckOut(“Online”,$null)
$spFile.Properties[“PublishingPageLayout”] = “/SiteURL/_catalogs/masterpage/WelcomeLinks.aspx”
$spFile.Update()
$spFile.CheckIn(“Update page layout via PowerShell”,[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)
$spWeb.Dispose()

Change page layout of all the pages:
If you want to change the page layout of all the pages then you can use the below PowerShell. Refered from here.

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

$siteLayouts = $pSite.GetPageLayouts($false)
$myLayout = $siteLayouts[“/_catalogs/masterpage/WelcomeLinks.aspx”]
#$myLayout
$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()

Hope this will be helpful.

Similar SharePoint 2013 Tutorials

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →

Leave a Reply