none
How to get a list of Search Result Sources using PowerShell? RRS feed

  • Question

  • Hi,

    Is there a way I can use PowerShell to get a full list of Search Result Sources in the SharePoint farm, including farm, site collection, and web level result sources?

    Thank you.

    Thursday, August 20, 2015 11:24 PM

Answers

  • You will have to handle the enumeration by feeding the enumerated sites and site collections to the SearchOwner, but here is how to get the Result Sources for the Farm:

    Add-PSSnapin Microsoft.SharePoint.PowerShell
      
    $ssa = Get-SPEnterpriseSearchServiceApplication
    $fedman = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($ssa)
      
    $searchOwner = Get-SPEnterpriseSearchOwner -Level Ssa  
    $filter = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectFilter($searchOwner)
    
    $filter.IncludeHigherLevel = $true
    
    $fedman.ListSources($filter,$true) | Select Name, Description, Active, Owner


    Matthew McDermott, MVP SharePoint

    • Marked as answer by Conway Liu Thursday, November 2, 2017 8:41 PM
    Thursday, March 2, 2017 10:03 PM

All replies

  • Hi,

    We can use the SourceId property in the KeywordQuery object to set which Result Source, and use the Query Transform to narrow search results.

    http://blog.mastykarz.nl/programmatically-working-keyword-search-queries-sharepoint-2013/

    https://technet.microsoft.com/en-us/library/Dn186229.aspx#BKMK_How_does_query_transform_affect_query

    You can also use Search REST API to get the lists, here is a tool for your reference:

    https://sp2013searchtool.codeplex.com/

    Best Regards,

    Dennis Guo


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Monday, August 24, 2015 2:40 AM
    Moderator
  • Thank you Dennis.

    But I'm not trying to perform search using a result source. Rather I'm trying to get a list of result sources that's already in the system.

    In Search Administration in Central Admin, when you run a Usage Report for Top Queries By Month, the report shows all the query text against the result source it was run against, even if the result source was created for a site collection or site.

    Having a farm of tons of site collections, and God know who has created result sources in some site collections, is there a command I can run either in PowerShell or C# that will just give me the full list of result sources and where they were created?

    Thank you for your help.

    Kind regards 


    • Edited by Conway Liu Monday, August 24, 2015 4:39 AM
    Monday, August 24, 2015 4:38 AM
  • You will have to handle the enumeration by feeding the enumerated sites and site collections to the SearchOwner, but here is how to get the Result Sources for the Farm:

    Add-PSSnapin Microsoft.SharePoint.PowerShell
      
    $ssa = Get-SPEnterpriseSearchServiceApplication
    $fedman = New-Object Microsoft.Office.Server.Search.Administration.Query.FederationManager($ssa)
      
    $searchOwner = Get-SPEnterpriseSearchOwner -Level Ssa  
    $filter = New-Object Microsoft.Office.Server.Search.Administration.SearchObjectFilter($searchOwner)
    
    $filter.IncludeHigherLevel = $true
    
    $fedman.ListSources($filter,$true) | Select Name, Description, Active, Owner


    Matthew McDermott, MVP SharePoint

    • Marked as answer by Conway Liu Thursday, November 2, 2017 8:41 PM
    Thursday, March 2, 2017 10:03 PM