I've recently created a bunch of custom query rules (in fact, promoted results) for my site collection, with custom keywords, titles, names, descriptions and URLs.

The format is:

CreateQueryRules -SiteUrl 'https://server' -Name 'UPS' -Synonyms 'UPS' -LinkTitle 'UPS' -LinkDescription 'UPS' -LinkUrl 'https://server2'

Here I suppress the whole code, meaning that the following parameters are passed to the function: site collection URL, query rule name, promoted result name, keywords and the URL (link) for promoted result.

During execution, I've made a mistake with -LinkUrl parameter and pass the URL as "server2", not "https://server2".

After the error occurs:

Exception calling "Update" with "0" argument(s): "Invalid URI: The format of the URI could not be determined."
At F:\_install\create_query_rule(best_bet).ps1:32 char:1SERVER2date()
+             ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : UriFormatException

I've checked the site collection under


From "For what context do you want to configure rules?" -> Select a result source -> All sources (from dropdown) and something went wrong :)

The error details are:

05/24/2017 17:41:39.61 w3wp.exe (SERVER:0x2848) 0x23F8 SharePoint Foundation Unified Logging Service 2m1i Verbose Adding event 8313 (category: Topology, product: SharePoint Foundation) to spam monitoring list 4cd1f49d-bf31-d015-53e9-8a3482f114fd
05/24/2017 17:41:39.61 w3wp.exe (SERVER:0x2848) 0x23F8 SharePoint Foundation General 8nca Medium Application error when access /_layouts/15/listqueryrules.aspx, Error=Invalid URI: The format of the URI could not be determined.  Server stack trace:      at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)     at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)     at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)     at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)     at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)    Exception rethrown at [0]:      at Microsoft.Office.Server.Search.Internal.UI.SearchObjectAdminPageBase.ErrorHandler(Object sender, EventArgs e)     at System.Web.UI.TemplateControl.OnError(EventArgs e)     at System.Web.UI.Page.HandleError(Exception e)     at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)     at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)     at System.Web.UI.Page.ProcessRequest()     at System.Web.UI.Page.ProcessRequest(HttpContext context)     at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()     at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 4cd1f49d-bf31-d015-53e9-8a3482f114fd

When I tried to delete this custom query rule(s), the following error occurred:

Exception calling "RemoveQueryRule" with "1" argument(s): "Invalid URI: The format of the URI could not be determined."
At line:3 char:1
+ $searchServiceApplication.RemoveQueryRule($qryRule)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : UriFormatException

I had the exact same issue after importing a batch of Promoted Results.

Here's the script I used that worked to remove the offending entries. The trick was to force remove the query action before removing the query rule using $qryRule.RemoveQueryAction($qryRule.AssignBestBetsAction)

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null)
  Write-Host "Loading SharePoint Powershell Snapin`r`n"
  Add-PSSnapin "Microsoft.SharePoint.Powershell"

$siteUrl = "http://home.contoso.com/"
$resultSourceName = "Local SharePoint Results"
$web = Get-SPWeb $siteUrl

$ssa = Get-SPServiceApplication -Name "Search Service"
$queryRuleManager = New-Object Microsoft.Office.Server.Search.Query.Rules.QueryRuleManager($ssa)

$site = Get-SPSite $siteUrl
$level = "SPWeb"

$searchObjectOwner = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectOwner($level, $web)
$searchObjectFilter = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectFilter($searchObjectOwner)
$federationManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($ssa)
$resultSource = $federationManager.GetSourceByName($resultSourceName,$searchObjectOwner)
$queryRules = $queryRuleManager.GetQueryRules($searchObjectFilter)

function DeleteAllPromotedResult([string]$ssaName)
    $customQueryRules = $queryRuleManager.GetQueryRules($searchObjectFilter) | ?{$_.Owner.Level -ne $ssaName}
    Write-Host "There are" $customQueryRules.Count "Customised Query Rules"
    foreach($qryRule in $customQueryRules) {
        Write-Host "Deleting Query Rule" $qryRule.DisplayName


#Delete all the Promoted Result

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.