Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ITProCorner/0649a7a84801d6c114c8a7a6a8636781 to your computer and use it in GitHub Desktop.
Save ITProCorner/0649a7a84801d6c114c8a7a6a8636781 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment