Update an exiting page to a new layout page and need to update all my sites page to the new layout page.
Code
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Site that I would like to implement the change on
$StartWeb="https://intranet.peelschools.org/ltss/pmo/PMLC"
#filter to only the sites that I want
$subsites = ((Get-SPWeb $StartWeb).Site).allwebs | ?{$_.url -like "$StartWeb*"}
$pWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($subsites)
$pSite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($subsites.Site)
#need the root of the site collection to get the layout page from
$rootSite = Get-SPSite https://intranet.peelschools.org
$site =$subsites
$lookForList = "Pages"
foreach($subsite in $subsites){
$spPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($subsite)
$pages = $spPubWeb.PagesList
$myLayout = $siteLayouts["/_catalogs/masterpage/PDSB/Content.aspx"]
#Add site content types to the list
$ctToAdd = $rootSite.RootWeb.ContentTypes["Intranet SP2013"]
$ct = $pages.ContentTypes.Add($ctToAdd)
write-host "Content type" $ct.Name "added to list" $pages.Title
foreach($item in $pages.Items)
{
$pubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item)
if ($pubPage.Title -ne "Forms" -and $pubPage.Title -ne "All Documents" -and $pubPage.Title -ne "Documents")
{
$pubPage.CheckOut()
$pubPage.Layout = $myLayout
# $pubPage.item["Show Resources in page"]=$true
$pubPage.
$pubPage.Update()
$pubPage.CheckIn("")
$pageFile = $pubPage.ListItem.File
$pageFile.Publish("")
}
}
Write-Host $subsite.url "is done"
}
$subsites.Dispose()
$rootsite.Dispose()