Skip to content

Instantly share code, notes, and snippets.

@chrisobriensp
Created December 3, 2013 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chrisobriensp/7779915 to your computer and use it in GitHub Desktop.
Save chrisobriensp/7779915 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link

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