SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 3 down vote accepted
 [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...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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