0

Via PowerShell, I would like to edit the page layout of all the publishing pages that live within a specific folder (or any subfolders of that folder) in the Pages library. I found this script that gets me most of the way there but I have no clue how filter based on folder.

$SPAssignment = Start-SPAssignment
$spWeb = Get-SPWeb("http://currentsitename/webname")
$spFile = $spWeb.GetFile("http://currentsitename/webname/Pages/Test-Page.aspx")
$spFile.CheckOut("Online",$null)
$spFile.Properties["PublishingPageLayout"] = "/_catalogs/masterpage/Block.aspx, Block"
$spFile.Update()
$spFile.CheckIn("Update page layout via PowerShell", [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)
Stop-SPAssignment $SPAssignment

This only has to be run one time, I'm not opposed to using a console application instead.

3
 [Microsoft.SharePoint.SPFolder]$folder = $spWeb.GetFolder($path);

 $sItems = $folder.folder.Files

 if($folder.Folder.Files.count -gt 0) 
 { 
        foreach($item in $sItems) 
        {

              $SPAssignment = Start-SPAssignment
              $item.CheckOut("Online",$null)
              $item.Properties["PublishingPageLayout"] = "/_catalogs/masterpage/Block.aspx, Block"
              $item.Update()
              $item.CheckIn("Update page layout via PowerShell", [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)
              Stop-SPAssignment $SPAssignment

        }
 }

For sub-folders inside the folder, you may need to apply recursive operation!

I haven't tried this, but this should work! You may need to modify at some places...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.