Quantcast
Channel: entwicklungsgedanken » SharePoint-Development
Viewing all articles
Browse latest Browse all 12

Changing the page layout of a search result page via Powershell in SharePoint 2010

$
0
0

This is a “quick hack” to change the layout of a search result page.

When the Publishing-Feature is disabled you are not able to change the layout via the UI. If you add a new page via “Create page” chances are high that you get a layout you don’t want.

Powershell comes to the rescue …

Add-PSSnapin Microsoft.SharePoint.Powershell -ea SilentlyContinue
clear
 
$w = Get-SPWeb http://path/to/website
$pages = $w.Lists["Pages"]
 
foreach($p in $pages.Items)
{
  # Condition can be arbitrary
  if($p.Title -eq "My Title")
  {
      $p.File.CheckOut()
      $p["PublishingPageLayout"] = "http://server/_catalogs/masterpage/searchresults.aspx"
      $p.Update()
      $p.File.CheckIn("Update page-layout via powershell")
  }
}

Viewing all articles
Browse latest Browse all 12

Trending Articles