Friday, 6 January 2017

Create Publishing Page using Custom PageLayout by PowerShell in SharePoint 2013

Hi - Today i will share the code for creating Publishing Page based on a custom Pagelayout using powershell


$siteUrl="ur site URL here"

$site = Get-spsite $siteUrl
$web = $site.OpenWeb()
$pubWeb =[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
#Name of the page layout. It can also be your custom template
$pl = $pubWeb.GetAvailablePageLayouts() | Where { $_.Name -eq "BlankWebPartPage.aspx" }
$newPage = $pubWeb.AddPublishingPage("newpage.aspx", $pl)
$newPage.CheckIn("")
$newPage.ListItem.File.Publish("")
$web.Dispose()

Happy coding..

No comments:

Post a Comment