Skip to content

Instantly share code, notes, and snippets.

@rheid
Created March 14, 2015 12:34
Show Gist options
  • Save rheid/182fb8f23db168f2aef0 to your computer and use it in GitHub Desktop.
Save rheid/182fb8f23db168f2aef0 to your computer and use it in GitHub Desktop.
Export SharePoint Managed Properties
#------------------------------------------------------------------------------------------------------
# Name: Export-SpSearchManagedProperties.ps1
# Description: This script will export create Crawled and Managed Properties from Enterprise Search
#
# Usage: Run the function with a required parameters
# By: Ivan Josipovic, Softlanding.ca
#------------------------------------------------------------------------------------------------------
Function Export-SpSearchManagedProperties([string]$SearchServiceApp,[string]$filename){
#Use This to ignore the out of the box managed properties
$IgnoreMappings = @("AboutMe","Account","AccountName","AssignedTo","Author","BaseOfficeLocation","BestBetKeywords","CategoryNavigationUrl","CollapsingStatus","Colleagues","contentclass","ContentsHidden","ContentSource","ContentType","CreatedBy","Department","Description","DisplayDate","DocComments","DocId","DocKeywords","DocSignature","DocSubject","DuplicateHash","EMail","EndDate","ExcludeFromSummary","ExpirationTime","FileExtension","Filename","FirstName","FollowAllAnchor","HierarchyUrl","HighConfidenceDisplayProperty1","HighConfidenceDisplayProperty10","HighConfidenceDisplayProperty11","HighConfidenceDisplayProperty12","HighConfidenceDisplayProperty13","HighConfidenceDisplayProperty14","HighConfidenceDisplayProperty15","HighConfidenceDisplayProperty2","HighConfidenceDisplayProperty3","HighConfidenceDisplayProperty4","HighConfidenceDisplayProperty5","HighConfidenceDisplayProperty6","HighConfidenceDisplayProperty7","HighConfidenceDisplayProperty8","HighConfidenceDisplayProperty9","HighConfidenceImageURL","HighConfidenceMatching","HighConfidenceResultType","HitHighlightedProperties","HitHighlightedSummary","HostingPartition","ImageDateCreated","Interests","IsDocument","JobTitle","Keywords","LastModifiedTime","LastName","Location","Memberships","MetadataAuthor","MobilePhone","ModifiedBy","NLCodePage","Notes","OfficeNumber","OrgNames","OrgParentNames","OrgParentUrls","OrgUrls","OWS_URL","parentLink","PastProjects","Path","PictureHeight","PictureThumbnailURL","PictureURL","PictureWidth","PreferredName","Priority","PrivateColleagues","Pronunciations","Purpose","Rank","RankDetail","RankingWeightHigh","RankingWeightLow","RankingWeightName","Responsibilities","Schools","SecondaryFileExtension","ServerRedirectedURL","ServiceApplicationID","SipAddress","Site","SiteID","SiteTitle","Size","Skills","SocialTagTextUrl","SPSiteURL","StartDate","Status","Title","UrlDepth","urn:schemas.microsoft.com:fulltextqueryinfo:cataloggroup","urn:schemas.microsoft.com:fulltextqueryinfo:sourcegroup","urn:schemas-microsoft-com:office:office#Description","urn:schemas-microsoft-com:office:office#ows_CrawlType","urn:schemas-microsoft-com:office:office#ows_ListTemplate","urn:schemas-microsoft-com:office:office#Subject","urn:schemas-microsoft-com:office:office#Title","urn:schemas-microsoft-com:publishing:Category","urn:schemas-microsoft-com:publishing:CategoryTitle","urn:schemas-microsoft-com:sharepoint:portal:area:CategoryUrlNavi","urn:schemas-microsoft-com:sharepoint:portal:area:Path","UserName","UserProfile_GUID","WebId","WikiCategory","WorkEmail","WorkPhone","YomiDisplayName")
#Uncomment the line below and comment the line above to export everything.
#$IgnoreMappings = ""
$ManagedPropreties = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $SearchServiceApp
add-content $filename "<?xml version=`"1.0`"?>"
add-content $filename "<ExportedPropreties>"
foreach ($MP in $ManagedPropreties){
[bool] $test = $true
foreach ($name in $IgnoreMappings){
if ($MP.Name -eq $name){
$test = $false
}
}
if ($test -eq $true){
add-content $filename "<ManagedProprety>"
add-content $filename "<Name>$($MP.Name)</Name>"
add-content $filename "<ManagedType>$($MP.ManagedType)</ManagedType>"
$Mappings = $MP.GetMappings()
foreach ($Mapping in $Mappings){
add-content $filename "<Mapping>"
add-content $filename "<CrawledPropset>$($Mapping.CrawledPropset)</CrawledPropset>"
$CP = $Mapping.CrawledPropertyName
if ($CP.Contains(":") -eq $true){
add-content $filename "<CrawledPropertyName>$($CP.SubString(1+$cp.lastindexof(":"),$cp.Length-$CP.LastIndexOf(":")-1))</CrawledPropertyName>"
} else {
add-content $filename "<CrawledPropertyName>$($cp)</CrawledPropertyName>"
}
add-content $filename "<CrawledPropertyVariantType>$($Mapping.CrawledPropertyVariantType)</CrawledPropertyVariantType>"
add-content $filename "</Mapping>"
}
add-content $filename "</ManagedProprety>"
}
}
add-content $filename "</ExportedPropreties>"
}
Export-SpSearchManagedProperties "Search Service" "ExportedProperties.xml"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment