Category Archives: SharePoint 2013

Export Query Rules Best Bets using PowerShell – SharePoint 2013

Published / by / Leave a Comment

Without using any custom code, Search service application administrators, site collection administrators, and site owners can help searches respond to the intent of users by creating query rules. In a query rule, you specify conditions and correlated actions. When a query meets the conditions in a query rule, the search system performs the actions specified in the rule to improve the relevance of the search results, such as by narrowing results or changing the order in which results are displayed.

We all know how hard it is to manage these one by one. Exporting these query rules to Excel, making the modifications and importing from Excel would save tremendous amount of time for Administrators.

Add-PSSnapin Microsoft.Sharepoint.Powershell;
$siteUrl = "";
$resultSourceName = "Local SharePoint Results";
$site = Get-SPWeb $siteUrl;
$web = Get-SPWeb $siteUrl;
$searchServiceApplication = Get-SPServiceApplication -Name "Search Service";
$searchOwner = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectOwner -ArgumentList @([Microsoft.Office.Server.Search.Administration.SearchObjectLevel]::SPSite,$site);
$searchObjectFilter = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectFilter($searchOwner);
$queryRuleManager = New-Object Microsoft.Office.Server.Search.Query.Rules.QueryRuleManager($searchServiceApplication);
$queryRules = $queryRuleManager.GetQueryRules($searchObjectFilter);
$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($searchServiceApplication)
$resultSource = $federationManager.GetSourceByName($resultSourceName,$searchObjectOwner)
$queryRules = $queryRuleManager.GetQueryRules($searchObjectFilter)
$promotedResultCollection = $searchServiceApplication.GetBestBets($searchObjectFilter)
$customQueryRules = $queryRuleManager.GetQueryRules($searchObjectFilter) | ?{$_.Owner.Level -ne $searchServiceApplication}
Write-Host "There are" $customQueryRules.Count "Customised Query Rules"
"Title `t Url `t Keywords `t Description" | out-file ExportQueryRules.csv
foreach($qryRule in $customQueryRules)
#Write-Host "Exporting Query Rule " $qryRule.DisplayName
#$queryAction = $qryRule.CreateQueryAction([Microsoft.Office.Server.Search.Query.Rules.QueryActionType]::AssignBestBet)
$termstring ="";
foreach ($term in $qryRule.QueryConditions.Terms)
$termstring += $term +";";
foreach ($bestbet in $qryRule.AssignBestBetsAction.BestBetIds)
$promotedResultCollection[$bestbet].Title + "`t" + $promotedResultCollection[$bestbet].Url.OriginalString+ "`t" +$termstring+ "`t" + $promotedResultCollection[$bestbet].Description | Out-File ExportQueryRules.csv -Append

SharePoint error “Cannot complete this operation” – Creating site from site tempalte

Published / by / Leave a Comment

The SharePoint application pages under the layouts folder uses the web.config file at the following location. Default timeout is 3600 and increase it will make the execution complete successfully. 

Location: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS

[wc_highlight color=”blue”]<httpRuntime executionTimeout=”18000″ />[/wc_highlight]


[wc_box color=”primary” text_align=”left”]

If you are using Physical Load Balancer like F5 then check for LANTIMEOUT, WANTIMEOUT and adjust them appropriately.




SharePoint 2013 prompts for login credentials while editing Publishing pages

Published / by / Leave a Comment

SharePoint 2013 uses a Distributed Cache Service to cache login tokens. In SharePoint 2010 Products, the login token is stored in the memory of each web front-end server. Each time a user accesses a specific web front-end server, it needs to authenticate. If you use network load balancers in front of your web front-ends, users need to authenticate for each web front-end server that is accessed behind the load balancer, causing possible multiple re-authentications.

The Distributed Cache depends on Windows Server AppFabric and old versions of it had lot of issues and is known to cause login prompts while editing SharePoint Pages. Follow the below steps to upgrade to latest version and login prompt issues will be resolved. You may have to restart the computer after you apply this cumulative update package.

  • Go to
  • Download the latest cumulative update
  • Copy it to the server and update app fabric