Create Publishing Page by Powershell
#input parameters
$siteUrl="https://mySiteCollection"
$fileName = "PowershellPage"
$pageLayout="/_catalogs/masterpage/RedirectPageLayout.aspx"
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint.Publishing")
# Get publishing web
$site = get-spsite $siteUrl
$web = $site.rootweb #or OpenWeb()
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
Write-Host “Creating $fileName”
# Create blank page
$newPage = $pWeb.AddPublishingPage()
$newPage.Update()
# Update the filename and other fields
$newPage.ListItem["BaseName"] = $fileName #$pageurl
$newPage.ListItem["Title"] = $fileName #$pagetitle
$newPage.ListItem["Page Content"] = "My powershell content" #$pagecontent
# Change page layout
$newPage.ListItem["PublishingPageLayout"] = $pageLayout
$newPage.ListItem["ContentTypeId"]=
'0x010100C568DB52D9D0A14D9B2FDCC96666E9F2057948130EC3DB064584E219954237AF390009FBB3819E595546BF3173275BBC22D10099977315E5C941F28E2B15B717582956'
#Add values to field from new page layout
$field=new-object Microsoft.Sharepoint.SPFieldUrlValue
$field.Url = "https://www.google.com"
$field.Description="My favorite"
$newPage.ListItem["RedirectUrl"]=$field
$newPage.ListItem.SystemUpdate()
write-host "Publishing page $fileName was succesfuly created."
# Dispose of the web
$web.Dispose()
#Get Publishing Page
#$page=$pWeb.GetPublishingPage("Pages/PsPage.aspx")
#Get Page layout of the page or other fields
#$page.ListItem["PublishingPageLayout"]