Updating SP2013 refiners using PowerShell

In SharePoint 2010, changes to the refiners were made using the the FilterCategoriesDefinition property of the refiners web part which held an XML blob.  In SharePoint 2013 we instead do this using the SelectedRefinementControlsJson property.  As the name implies, the configuration is now in JSON format.  Conveniently PowerShell 3.0 now includes the ConvertTo- and ConvertFrom-Json cmdlets that make this a breeze.  Here’s a code snippet that changes the display name for the Last Modified Date refiner to “Mod Time” (all relevant error handling removed for clarity):

# Get our page and check it out
$spweb = Get-SPWeb "http://da-server/search/"
$page = $spweb.GetFile("Pages/results.aspx")

# Find the Refinement web part
$webPartManager = $spweb.GetLimitedWebPartManager("http://da-server/search/Pages/results.aspx", [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$rwp = $webpartmanager.webparts | ? { $_.title -eq 'Refinement' }

# Refiners are updated by changing the JSON
$j = $rwp.SelectedRefinementControlsJson | ConvertFrom-Json
$j.refinerConfigurations | % { if ($_.propertyName -eq 'LastModifiedTime') { $_.displayName = 'Mod Time'; }
$rwp.SelectedRefinementControlsJson = ConvertTo-Json $j -Compress

# Save our changes
$webpartmanager.SaveChanges($rwp)          # save changes to webpart
$page.CheckIn('Changed last mod refiner') $page.Publish('Changed last mod refiner')

Now, after reloading my search results page, I see the new display name:


Comments (9)

  1. Excellent stuff. Thanks for sharing.

  2. Anonymous says:

    Nice post!
    I’d like to add a new refiner to this web part.
    How would you do it via PowerShell?

  3. Anonymous says:

    got it ..  one line is missing in above snippt. under

    # Save our chnages

    $webpartmanager.SaveChanges($rwp)                    # save changes to webpart.

    Thanks Matt.. you post solved my problem.

  4. Anonymous says:


    All commands run successfully, I have done crawl again. but still can't see the difference.

  5. BostonGeorge says:

    You're missin "}" in line:

    $j.refinerConfigurations | % { if ($_.propertyName -eq 'LastModifiedTime') { $_.displayName = 'Mod Time'; }

    at the end.

    Besides trying to convert it back to JSON gives:

    Exception setting "SelectedRefinementControlsJson": "No parameterless constructor defined for type of 'Microsoft.Office.Server.Search.WebControls.RefinementControl[]'."

  6. Mani says:

    Carolina Bauque: Were you able to achieve adding new refiner to a web part. if yes could you please share the code

  7. Thanks for the great post!

    In case it helps others, I was able to update the refiners using the following code:

    $newRefinerConfigurations = @()
    $newJsonObject = @{}

    $jsonString = @"
    "sortBy" : 0,
    "sortOrder" : 0,
    "maxNumberRefinementOptions" : 15,
    "propertyName" : "",
    "type" : "Text",
    "displayTemplate" : "~sitecollection/_catalogs/masterpage/Display Templates/Filters/Filter_Default.js",
    "displayName" : "",
    "useDefaultDateIntervals" : false,
    "aliases" : [],
    "refinerSpecStringOverride" : "",
    "intervals" : null

    $newRefinerJson = ConvertFrom-Json $jsonString
    $newRefinerJson.propertyName = ""
    $newRefinerJson.displayName = ""
    $newRefinerConfigurations += $newRefinerJson

    (add other refiners here..)

    $newJsonObject.refinerConfigurations = $newRefinerConfigurations

    $rwp.SelectedRefinementControlsJson = ConvertTo-Json $newJsonObject -Depth 3 -Compress


  8. Badajoz says:

    Thanks very much

Skip to main content