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.Properties["PublishingPageLayout"] = "/_catalogs/masterpage/Block.aspx, Block"
$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.

| improve this question | | | | |
 [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.Properties["PublishingPageLayout"] = "/_catalogs/masterpage/Block.aspx, Block"
              $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...

| improve this answer | | | | |

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.