locked
Unable to Run Search Settings Export in Local Powershell Due to Exception calling "ExecuteQuery" with "0" argument(s): "Unable to connect to the remote server" RRS feed

  • Question

  • I'm attempting to run a script that exports the search settings using Microsoft.SharePoint.Client.Search.Portability.searchconfigurationportability

    It works great in my development environment (single SP 2013 server), but when I try to run in TEST (multi-server farm) or UAT (single server again) I get this error:

    Exception calling "ExecuteQuery" with "0" argument(s): "Unable to connect to the remote server"

    At C:\scripts_powershell\ExportSearchSettingsToXML.ps1:20 char:1

    + $context.ExecuteQuery()

    + ~~~~~~~~~~~~~~~~~~~~~~~

        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

        + FullyQualifiedErrorId : WebException

    I'm not sure why it appears to be seeing this script as remote when I'm on the actual server. I thinking this may be due to the double-hop issue, but not sure. I've tried passing credentials in with no luck. The output file is created, but it's empty. It appears to pull the context for the site correctly as well, it seems to be the searchconfigurationportability it's snagging on. Script is as follows:

    $computer="<computername>"
    $sitename = "<sitename>"

    $outputfile="C:\scripts_powershell\output\"+$computer+"_SearchSchemaExport.xml"
    [reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") | Out-Null
    [reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime") | Out-Null
    [reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.search") | Out-Null

    $username = Read-Host -Prompt "username" 
    $password = Read-Host -Prompt "Password for username" -AsSecureString

    $context = New-Object Microsoft.SharePoint.Client.ClientContext($sitename)
    $context.Credentials = New-Object System.Net.NetworkCredential($username, $password)

    $searchConfigurationPortability = New-Object Microsoft.SharePoint.Client.Search.Portability.searchconfigurationportability($context)
    $owner = New-Object Microsoft.SharePoint.Client.Search.Administration.searchobjectowner($context,"SSA")
    $value = $searchConfigurationPortability.ExportSearchConfiguration($owner)
    $context.ExecuteQuery()
    [xml]$schema = $value.Value
    $schema.OuterXml | Out-File $outputfile -Encoding UTF8

    Any help would be appreciated. Most references to this error point to credentials for sharepointonline, but we're not using sharepointonline.

    Wednesday, September 21, 2016 4:09 PM

Answers

  • Disregard. Solved this. We have two URLs for our site and while technically I can connect to both, I needed the HTTPS version to allow it to connect to the search settings. Now to figure out how to get the import to work correctly.
    • Marked as answer by C. Curtiss Wednesday, September 21, 2016 10:24 PM
    Wednesday, September 21, 2016 10:24 PM