Created
March 14, 2015 12:33
-
-
Save rheid/9e61f1ff7cb2fd08ddcd to your computer and use it in GitHub Desktop.
Import SharePoint Managed Properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#------------------------------------------------------------------------------------------------------ | |
# Name: Import-SpSearchManagedProperties.ps1 | |
# Description: This script will Import create Crawled and Managed Properties from Enterprise Search | |
# | |
# Usage: Run the function with a required parameters | |
# By: Ivan Josipovic, Softlanding.ca | |
#------------------------------------------------------------------------------------------------------ | |
Function Import-SpSearchManagedProperties([string]$SearchServiceApplication,[string]$FileName) | |
[System.Xml.XmlDocument] $xd = new-object System.Xml.XmlDocument | |
$xd.load(resolve-path($FileName)) | |
$nodelist = $xd.selectnodes("/ExportedPropreties/ManagedProprety") | |
$searchapp = Get-SPEnterpriseSearchServiceApplication $SearchServiceApplication | |
$category = Get-SPEnterpriseSearchMetadataCategory –Identity SharePoint -SearchApplication $searchapp | |
#Create Crawled Propreties | |
foreach ($Node in $nodelist) { | |
$Name = $node.selectSingleNode("Name") | |
$type = 1 | |
$ManagedType = $node.selectSingleNode("ManagedType") | |
switch ($ManagedType.innertext) | |
{ | |
"Text" {$type = 1} | |
"Integer" {$type = 2} | |
"Decimal" {$type = 3} | |
"DateTime" {$type = 4} | |
"YesNo" {$type = 5} | |
"Binary" {$type = 6} | |
} | |
$managedproperty = New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Name $Name.innertext -Type $type | |
$managedproperty.EnabledForScoping = $true | |
$managedproperty.PutInPropertyBlob = $true | |
$managedproperty.update() | |
$Mappings = $node.selectnodes("Mapping") | |
foreach ($Mapping in $Mappings){ | |
$CrawledPropset = $Mapping.selectSingleNode("CrawledPropset") | |
$CrawledPropertyName = $Mapping.selectSingleNode("CrawledPropertyName") | |
$CrawledPropertyVariantType = $Mapping.selectSingleNode("CrawledPropertyVariantType") | |
$crawledproperty = New-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $category -VariantType $CrawledPropertyVariantType.innertext -PropSet $CrawledPropset.innertext -Name $CrawledPropertyName.innertext -IsNameEnum $false | |
$cp = get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Name $CrawledPropertyName.innertext | |
New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchapp -ManagedProperty $managedproperty -CrawledProperty $cp | |
} | |
} | |
write-host "Done" | |
} | |
Import-SpSearchManagedProperties "Search Services Application" "ExportedProperties.xml" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment