Set Search Results web part Fetched properties by PowerShell

15/02/2018 12:48

Once we made typo in Core Search Results (SP 2010) web part in Fetched properties xml. This caused error of whole page (not only web part), so page was not editable any more and web part properties couldn't be edited any more via UI. SharePoint Designer also didn't allow to edit this page with web part. So we created following script to update Fetched properties value to correct xml and page was then editable again.

 

Add-Pssnapin microsoft.sharepoint.powershell -ea 0
$assembly=[void][reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
 
#web, where is your web part
$webUrl = "https://intranettest/search"
$pageUrl = $webUrl + "/Pages/peopleresults.aspx"
$columnsXml = 
'<Columns>  <Column Name="WorkId"/>  <Column Name="UserProfile_GUID"/>  <Column Name="AccountName"/>  <Column Name="PreferredName" HitHighLight="true"/>  <Column Name="YomiDisplayName" HitHighLight="true"/>  <Column Name="JobTitle" HitHighLight="true"/>  <Column Name="Department" HitHighLight="true"/>  <Column Name="WorkPhone" HitHighLight="true"/>  <Column Name="OfficeNumber" HitHighLight="true"/>  <Column Name="PictureURL"/> <Column Name="OrgUrls"/>  <Column Name="OrgParentNames" HitHighLight="true"/>  <Column Name="OrgParentUrls"/>  <Column Name="Memberships" HitHighLight="true"/>  <Column Name="AboutMe" HitHighLight="true"/>  <Column Name="BaseOfficeLocation" HitHighLight="true"/>  <Column Name="ServiceApplicationID"/>  <Column Name="SocialDistance"/></Columns>';
 
 
$web = Get-SPWeb $webUrl
 
#initialize the webpart-manager and locate it to the page
 
$webpartmanager = $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
 
#see list of web parts on the page
$webpartmanager.WebParts | select Title
   
  
#see selected web part on the page
$webpart = $webpartmanager.WebParts[4]
  
#see specific property value of wp (e. g.'ConfigurationListuGuid' property)
$webpart.Title
$webpart.DisplayTitle
$webpart.ConfigurationListGuid #this is custom web browsable property)
 
$webpart.SelectColumns
   
#To update search results web part SelectColumns property, following condition must be met
  
#1. The "SelectColumns" (Fetched Properties) string may not be Null or empty;
#2. The "PropertiesToRetrieve" must be Null or Empty;
#3. "UseLocationVisualization" must be false.
 
$webpart > c:\temp\searchwpobject.txt
 
$webpart. UseLocationVisualization = $false;
$webpart.PropertiesToRetrieve = '';
$webpart.SelectColumns = $columnsXml;
 
$webpartmanager.SaveChanges($webpart)
Add-Pssnapin microsoft.sharepoint.powershell -ea 0
$assembly=[void][reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c")
 
#web, where is your web part
$webUrl = "https://intranettest/search"
$pageUrl = $webUrl + "/Pages/peopleresults.aspx"
$columnsXml = 
'<Columns> <Column Name="hbroutofofficeinfo"/> <Column Name="LastName"/>  <Column Name="cPeoplePager"/>  <Column Name="cCompany"/>  <Column Name="cCostCenterCode"/>  <Column Name="cCompanyCode"/>  <Column Name="cCostCenterName"/>  <Column Name="cPeopleSkype"/>  <Column Name="WorkId"/>  <Column Name="UserProfile_GUID"/>  <Column Name="AccountName"/>  <Column Name="PreferredName" HitHighLight="true"/>  <Column Name="YomiDisplayName" HitHighLight="true"/>  <Column Name="JobTitle" HitHighLight="true"/> <Column Name="JobTitle1" HitHighLight="true"/><Column Name="JobTitle2" HitHighLight="true"/><Column Name="JobTitle3" HitHighLight="true"/><Column Name="JobTitle4" HitHighLight="true"/>  <Column Name="Department" HitHighLight="true"/>  <Column Name="WorkPhone" HitHighLight="true"/>  <Column Name="OfficeNumber" HitHighLight="true"/>  <Column Name="PictureURL"/>  <Column Name="HierarchyUrl"/>  <Column Name="WorkEmail" HitHighLight="true"/>  <Column Name="Path"/>  <Column Name="HitHighlightedSummary"/>  <Column Name="HitHighlightedProperties"/>  <Column Name="Responsibility" HitHighLight="true"/>  <Column Name="Skills" HitHighLight="true"/>  <Column Name="SipAddress" HitHighLight="true"/>  <Column Name="Schools" HitHighLight="true"/>  <Column Name="PastProjects" HitHighLight="true"/>  <Column Name="Interests" HitHighLight="true"/>   <Column Name="OrgNames" HitHighLight="true"/>  <Column Name="OrgUrls"/>  <Column Name="OrgParentNames" HitHighLight="true"/>  <Column Name="OrgParentUrls"/>  <Column Name="Memberships" HitHighLight="true"/>  <Column Name="AboutMe" HitHighLight="true"/>  <Column Name="BaseOfficeLocation" HitHighLight="true"/>  <Column Name="ServiceApplicationID"/>  <Column Name="SocialDistance"/></Columns>';
 
 
$web = Get-SPWeb $webUrl
 
#initialize the webpart-manager and locate it to the page
 
$webpartmanager = $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
 
#see list of web parts on the page
$webpartmanager.WebParts | select Title
   
  
#see selected web part on the page
$webpart = $webpartmanager.WebParts[4]
  
#see specific property value of wp (e. g.'ConfigurationListuGuid' property)
$webpart.Title
$webpart.DisplayTitle
$webpart.ConfigurationListGuid #this is custom web browsable property)
 
$webpart.SelectColumns
   
#To update search results web part SelectColumns property, following condition must be met
  
#1. The "SelectColumns" (Fetched Properties) string may not be Null or empty;
#2. The "PropertiesToRetrieve" must be Null or Empty;
#3. "UseLocationVisualization" must be false.
 
$webpart > c:\temp\searchwpobject.txt
 
$webpart. UseLocationVisualization = $false;
$webpart.PropertiesToRetrieve = '';
$webpart.SelectColumns = $columnsXml;
 
$webpartmanager.SaveChanges($webpart)