Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 2 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.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...

share|improve this answer
add comment

Your Answer

 
discard

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.