Create New Result Source for Federated Search using PowerShell

PowerShell script to Create 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)

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

$ResultSource = $FederationManager.CreateSource($SearchOwner)
$ResultSource.Name = $ResultSourceName
$ResultSource.ConnectionUrlTemplate = "{searchTerms}&format=rss&Market=en-us"
$ResultSource.ProviderId = $FederationManager.ListProviders()['OpenSearch Provider'].Id
$ResultSource.CreateQueryTransform($queryProperties, $query)

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

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

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

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

  • November 29, 2016 at 2:49 AM

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


Leave a Reply