none
SharePoint 2016 Search Results using Powershell RRS feed

  • Question

  • I'm trying to get around a specific issue I have using powershell to search my SP2016 farm.

    My script contains basically the code below;

    The issue I have:

    1) per $Keyword crawl, I get exactly 5000 records

    2) per $keyword crawl, I get the same 5000 records

    3) When I search in my SharePoint Search Centre using the same user (as running the powershell script) I get about 1500 results

    My Questions:

    1) As Powershell is all I can use, what am I overlooking in my script?

    2) How can I overcome the 5000 records issue, as the MaxRowLimit has already been increased?

    3) Why am I getting 5000 results as I should only see 1500?

    $site = Get-SPSite http://localhost
    $keywordQuery = New-Object Microsoft.Office.Server.Search.Query.KeywordQuery($site)
    $keyword = Read-Host “Search Term”
    $keywordQuery.QueryText = $keyword
    $searchExec = New-Object Microsoft.Office.Server.Search.Query.SearchExecutor
    $searchResults = $searchExec.ExecuteQuery($keywordQuery)

    Wednesday, January 15, 2020 3:47 PM

All replies

  • Hi,

    I’ve tested a sample PowerShell script in my SharePoint environment with multiple keywords. It turns out the number of search results returned in PowerShell is the same as the number in Search Center.

    For example, when I set $keyword = “SharePoint”, it returns 26 results, and “Documents” returns 48 results. Please note that in search center, the number on the first page of search results is not necessary the exact number of search results.

    So, to answer your question:

    1. What keywords did you use in the PowerShell script? You get more results from PowerShell possibly because you have used different keywords from search center.

    Also, you can check if you have modified the default Result Sources to accept additional query in the search center.

    2. You can change the property “MaxRowLimit” with PowerShell. See the sample script below:

    $ssa = Get-SPEnterpriseSearchServiceApplication
    $ssa.MaxRowLimit = 10000
    $ssa.Update()

    10000 is the supported boundary for “MaxRowLimit”. However, I don’t think you can get 10000 results back due to internal limits to SharePoint.

    Here’s your reference.

    Software boundaries and limits for SharePoint Servers 2016 and 2019.

    https://docs.microsoft.com/en-us/sharepoint/install/software-boundaries-and-limits-0

    Here’s the reference for the PowerShell script.

    Get Search Results in SharePoint 2013 using PowerShell.

    Please note: Microsoft provides third-party contact information to help you find technical support. This contact information may change without notice. Microsoft does not guarantee the accuracy of this third-party contact information.

    Best regards,

    Chelsea Wu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Thursday, January 16, 2020 7:06 AM
  • Hi, thx for the reply,

    I already increased the MaxRowLimit, but when I go above 5000, the search qeuries in powershell fail with the same error with the error "Exception calling "ExecuteQuery" with "0" argument(s): "The operation has timed out after (0 - 15) seconds"

    + as I said I get 5000 records in Powershell but the Search Centre returns far less + a praticular item i took as a testcase, I can see in that SharePoint but not in the Powershell resultset

    for me it's a big mystery.

    Thursday, January 16, 2020 8:25 AM
  • Hi,

    As I mentioned in the last reply, it is not recommended to raise the value of “MaxRowLimit” too high since there are internal limits to SharePoint and it will lead to performance issue.

    The reason why you get far more records in PowerShell than Search Centre might be that you are using different keywords searching in the two scenarios.

    A few things you can check:

    1. Replace the value for $keyword = Read-Host “Search Term” and see if you can get different results from this test.

    2. Make sure you have run a full crawl in Central Administration > Search Service Application > Content Sources before searching.

    3. You can check System Event Viewer or ULS logs when searching to rule out potential error on SharePoint server.

    Best regards,

    Chelsea Wu


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Friday, January 17, 2020 7:50 AM
  • Hi,

    Please remember to update this thread if you have any progress.

    Thank you for your understanding.

    Best regards,

    Chelsea Wu 

    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, January 20, 2020 1:57 AM