SharePoint 2013 Search: Managing Query Rules with PowerShell

One thing I've noticed about Query Rules, Search Admins are really good at creating Query Rules... not so good at deleting them.  Query Rules become difficult to manage when the number of rules in the environment grows to several dozen, hundreds or even thousands.

As content and relevancy change with time, Query Rules may become invalid or unnecessary.  For example, a Promoted Result Query Rule (Best Bet) may now point to a resource that no longer exists or the document a Promoted Result points to which was previously buried deep in the search results is now the #1 result.

To this end I created a script that will help the Search Admin identify and delete "invalid" Query Rules.  The intention of the script is to identify three basic use cases, log and, if desired, delete the logged Query Rules.  The use cases are:

  1. The URL in a Promoted Result action of the Query Rule is no longer valid.
  2. The Promoted Result appears in the top search results.
  3. The Query Rule no longer has Actions.

The script may be downloaded from the TechNet Script Gallery.  Click on over to to learn more. 

Comments (1)

  1. Geet says:

    Hi Eric,

    Thanks for the script. Actually I was trying to create Query rules with Promoted results for a particular result source using powershell. During that I executed a script which was creating query rules fine but changed few configurations which resulted in error "Invalid URI: Format of URI cannot be determined". I could not able to access the query rules for that result source from browser and I tried using your script to list the queryrules and I received the same error when I executed the following command. DO you have any idea how to deal with this?

    .Test-BestBetQueryRules.ps1 -Log -Mode RulesWithoutActions -Level Site -SiteURL http://mysiteurl

    TestRules_Empty : Invalid URI: The format of the URI could not be determined.

Skip to main content