Create New Result Source for Federated Search using PowerShell

The Federated search gathers search results from multiple search engines and presents them on a single page. Creating Federated Search Results in SharePoint is explained in another article: How to Create Federated Search Results in SharePoint 2016? This post targets the PowerShell script to create a new result source for Federated search results:

Here is the PowerShell script to create a new result source for Federated search:

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

#create a new result source at Search Service Application
$SearchServiceApplication = Get-SPEnterpriseSearchServiceApplication 
$FederationManager = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($SearchServiceApplication)

$SearchOwner = Get-SPEnterpriseSearchOwner -Level Ssa
$ResultSourceName ="Bing Search Result Source"

#For Site Level Result Source, Use:
#$SiteCollection = Get-SPSite $SiteUrl -ErrorAction SilentlyContinue
#$SearchOwner = Get-SPEnterpriseSearchOwner -Level SPSite -SPSite $SiteCollection

#Check if the Result Source is already exists
$ResultSource = $FederationManager.GetSourceByName($ResultSourceName,$SearchOwner)
if($ResultSource)
{
    $FederationManager.RemoveSource($ResultSource)
}

# create a new result source
$Query = "{SearchTerms}"

$ResultSource = $FederationManager.CreateSource($SearchOwner)
$ResultSource.Name = $ResultSourceName
$ResultSource.ConnectionUrlTemplate = "https://www.bing.com/search?q={searchTerms}&format=rss&Market=en-us"
$ResultSource.ProviderId = $FederationManager.ListProviders()['OpenSearch Provider'].Id
$ResultSource.CreateQueryTransform($queryProperties, $query)
$ResultSource.Commit()

Write-host Result Source: $ResultSourceName has been created successfully!

Related post: How to Create Result Source in SharePoint 2013?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

One thought on “Create New Result Source for Federated Search using PowerShell

  • For level site, please help check, i think:
    $SearchOwner = Get-SPEnterpriseSearchOwner -Level SPSite -SPWeb $RootSiteCollection.RootWeb

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *