kwizcom banner advertisement

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)
if($ResultSource)
{
    $FederationManager.RemoveSource($ResultSource)
}

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

$ResultSource = $FederationManager.CreateSource($SearchOwner)
$ResultSource.Name = $ResultSourceName
$ResultSource.ConnectionUrlTemplate = "http://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
Create New Result Source for Federated Search using PowerShell Create New Result Source for Federated Search using PowerShell Reviewed by Salaudeen Rajack on September 25, 2014 Rating: 5

1 comment:

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

    ReplyDelete

Please Login and comment to get your questions answered!

Powered by Blogger.