SharePoint 2013: fix for “This page is not using a valid page layout” powershell – can’t edit publishing page

filter Get-PublishingPages
{
$pubweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($_)
$query = new-object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = “Scope=’Recursive'”

try
{
$pages = $pubweb.GetPublishingPages($query)

foreach($page in $pages)
{
$spFile = $_.GetFile($page.uri.originalstring)
$oldproperty = $spFile.Properties[“PublishingPageLayout”]

$newproperty = $oldproperty -replace “https://newContoso.parsons.com”, “https://Contoso.parsons.com”

$newproperty

$spFile.CheckOut(“Online”,$null)
$spFile.Properties[“PublishingPageLayout”] =$newproperty
$spFile.Update()
$spFile.CheckIn(“Update page layout via PowerShell”,[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)
}

}
catch{}
}

$sites = Get-SpSite -WebApplication https://Contoso.parsons.com
foreach($site in $sites)
{
$webs = Get-SpWeb -site $site -Limit All
foreach($web in $webs)
{

$url=$web.url
get-spweb $url | Get-PublishingPages

}
}

Leave a Reply

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