Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PS + CSOM to import search schema XML (e.g. managed property definitions)..
. .\TopOfScript.ps1
# need some extra types bringing in for this script..
Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Search.dll"
# TODO: replace this path with yours..
$pathToSearchSchemaXmlFile = "C:\COB\Cloud\PS_CSOM\XML\COB_TenantSearchConfiguration.xml"
# we can work with search config at the tenancy or site collection level:
#$configScope = "SPSiteSubscription"
$configScope = "SPSite"
$searchConfigurationPortability = New-Object Microsoft.SharePoint.Client.Search.Portability.SearchConfigurationPortability($clientContext)
$owner = New-Object Microsoft.SharePoint.Client.Search.Administration.SearchObjectOwner($clientContext, $configScope)
[xml]$searchConfigXml = Get-Content $pathToSearchSchemaXmlFile
$searchConfigurationPortability.ImportSearchConfiguration($owner, $searchConfigXml.OuterXml)
$clientContext.ExecuteQuery()
Write-Host "Search configuration imported" -ForegroundColor Green
@nielsverhoeven

This comment has been minimized.

Copy link

@nielsverhoeven nielsverhoeven commented Apr 23, 2015

When i try to run this script I get the following error when executing "$searchConfigurationPortability = New-Object Microsoft.SharePoint.Client.Search.Portability.SearchConfigurationPortability($clientContext)" :

New-Object : Cannot find an overload for "SearchConfigurationPortability" and the argument count: "1".
At D:\Install\CDMS_Release_1.2_20150421_084744\SetUpManagedProperties.ps1:33 char:35

  • $searchConfigurationPortability = New-Object Microsoft.SharePoint.Client.Search. ...
  • - CategoryInfo          : InvalidOperation: (:) [New-Object], MethodException
    - FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand
    
    

Do you know what to do in this case?

@givenscj

This comment has been minimized.

Copy link

@givenscj givenscj commented Mar 9, 2016

You are using mixed versions of the CSOM library dlls. Make sure they are the same version 15 vs 16, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment