<#
.SYNOPSIS
Exports Search Metadata Mappings to an XmlDocument
.DESCRIPTION
This method can be used to retrieve Search Metadata Mappings from an existing farm.
The syntax can also be used as documentation of a farm
.EXAMPLE
$managedProperties | % {
New-Object PSobject -Property @{
Mapping = Get-SPEnterpriseSearchMetadataMapping -SearchApplication (Get-SPEnterpriseSearchServiceApplication) -ManagedProperty $_
ManagedPropertyName = $_.Name }
} | Export-SPEnterpriseSearchMetadataMapping | % {
$node = $xmlMappings.ImportNode($_.Mapping,$false)
$xmlMappings.DocumentElement.AppendChild($node)
} | Out-Null
.LINK
Export-SPEnterpriseSearchMetadataMapping
#>
function Export-SPEnterpriseSearchMetadataMapping
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline = $true)]
[Microsoft.Office.Server.Search.Administration.Mapping] $Mapping,
[Parameter(Mandatory=$true, ValueFromPipeline = $true)]
[string] $ManagedPropertyName
)
process
{
[xml]$xml = "<Mapping />"
$xml.DocumentElement.SetAttribute('ManagedProperty', $ManagedPropertyName)
$xml.DocumentElement.SetAttribute('CrawledProperty', $Mapping.CrawledPropertyName)
$xml.DocumentElement.SetAttribute('PropertySet', $Mapping.CrawledPropset)
$xml.DocumentElement.SetAttribute('VariantType', $Mapping.CrawledPropertyVariantType)
$xml
}
}
<#
.SYNOPSIS
Exports Search Metadata Managed Properties to an XmlDocument
.DESCRIPTION
This method can be used to retrieve Search Metadata Managed Properties from an existing farm.
The syntax can also be used as documentation of a farm
.EXAMPLE
$managedProperties | Export-SPEnterpriseSearchMetadataManagedProperty | % {
$node = $xmlManagedProperties.ImportNode($_.ManagedProperty,$false)
$xmlManagedProperties.DocumentElement.AppendChild($node)
} | Out-Null
.LINK
Export-SPEnterpriseSearchMetadataManagedProperty
#>
function Export-SPEnterpriseSearchMetadataManagedProperty
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline = $true)]
[Microsoft.Office.Server.Search.Cmdlet.ManagedPropertyPipeBind] $ManagedProperty
)
process
{
[xml]$xml = "<ManagedProperty />"
$xml.DocumentElement.SetAttribute('Name', $_.Name)
$xml.DocumentElement.SetAttribute('Description', $_.Description)
$xml.DocumentElement.SetAttribute('Type', [int]$_.ManagedType)
$xml.DocumentElement.SetAttribute('MaxCharactersInPropertyStoreIndex', $_.MaxCharactersInPropertyStoreIndex)
$xml.DocumentElement.SetAttribute('FullTextQueriable', $_.FullTextQueriable)
$xml.DocumentElement.SetAttribute('HasMultipleValues', $_.HasMultipleValues)
$xml.DocumentElement.SetAttribute('Retrievable', $_.Retrievable)
$xml.DocumentElement.SetAttribute('EnabledForScoping', $_.EnabledForScoping)
$xml.DocumentElement.SetAttribute('RemoveDuplicates', $_.RemoveDuplicates)
$xml.DocumentElement.SetAttribute('PutInPropertyBlob', $_.PutInPropertyBlob)
$xml.DocumentElement.SetAttribute('QueryPropertyBlob', $_.QueryPropertyBlob)
$xml.DocumentElement.SetAttribute('RespectPriority', $_.RespectPriority)
$xml
}
}
<#
.SYNOPSIS
Exports Search Metadata Crawled Properties to an XmlDocument
.DESCRIPTION
This method can be used to retrieve Search Metadata Crawled Properties from an existing farm.
The syntax can also be used as documentation of a farm
.EXAMPLE
$CrawledProperty | Export-SPEnterpriseSearchMetadataCrawledProperty | % {
$node = $xmlCrawledProperties.ImportNode($_.CrawledProperty,$false)
$xmlCrawledProperties.DocumentElement.AppendChild($node)
} | Out-Null
.LINK
Export-SPEnterpriseSearchMetadataCrawledProperty
#>
function Export-SPEnterpriseSearchMetadataCrawledProperty
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, ValueFromPipeline = $true)]
[Microsoft.Office.Server.Search.Cmdlet.CrawledPropertyPipeBind] $CrawledProperty
)
process
{
[xml] $xml = "<CrawledProperty />"
$xml.DocumentElement.SetAttribute('Name', $_.Name)
$xml.DocumentElement.SetAttribute('Category', $_.CategoryName)
$xml.DocumentElement.SetAttribute('PropertySet', $_.PropSet)
$xml.DocumentElement.SetAttribute('VariantType', $_.VariantType)
$xml.DocumentElement.SetAttribute('IsMappedToContents', $_.IsMappedToContents)
$xml
}
}
<#
.SYNOPSIS
Exports Search Metadata to an XmlDocument
.DESCRIPTION
This method can be used to retrieve Search Metadata from an existing farm.
The syntax can also be used as documentation of a farm
.EXAMPLE
[xml]$SearchMetadata = Export-SPEnterpriseSearchMetadata -CrawledProperty $crawledProperties -ManagedProperty $managedProperties
$SearchMetadata.OuterXml | Out-File -FilePath "MetadataMappings.xml" -Encoding UTF8
.LINK
Export-SPEnterpriseSearchMetadata
#>
function Export-SPEnterpriseSearchMetadata
{
[CmdletBinding()]
param(
[Parameter(Mandatory=$true)]
[Microsoft.Office.Server.Search.Administration.CrawledProperty[]] $CrawledProperty,
[Parameter(Mandatory=$true)]
[Microsoft.Office.Server.Search.Administration.ManagedProperty[]] $ManagedProperty
)
process
{
[xml]$xml = "<Metadata />"
[xml]$xmlCrawledProperties = "<CrawledProperties />"
# append CrawledProperty to CrawledProperties node
$CrawledProperty | Export-SPEnterpriseSearchMetadataCrawledProperty | % {
$node = $xmlCrawledProperties.ImportNode($_.CrawledProperty,$false)
$xmlCrawledProperties.DocumentElement.AppendChild($node)
} | Out-Null
# append to MetaData
$xml.DocumentElement.AppendChild($xml.ImportNode($xmlCrawledProperties.CrawledProperties, $true)) | Out-Null
[xml]$xmlManagedProperties = "<ManagedProperties />"
# append ManagedProperty to ManagedProperties node
$managedProperties | Export-SPEnterpriseSearchMetadataManagedProperty | % {
$node = $xmlManagedProperties.ImportNode($_.ManagedProperty,$false)
$xmlManagedProperties.DocumentElement.AppendChild($node)
} | Out-Null
# append to Metadata
$xml.DocumentElement.AppendChild($xml.ImportNode($xmlManagedProperties.ManagedProperties, $true)) | Out-Null
[xml]$xmlMappings = "<Mappings />"
foreach ( $managedProperty in $managedProperties )
{
$mappings = Get-SPEnterpriseSearchMetadataMapping -SearchApplication (Get-SPEnterpriseSearchServiceApplication) -ManagedProperty $managedProperty
# A managed property can have multiple mappings
if ( $mappings -is [Array] )
{
foreach ($mapping in $mappings)
{
$xmlMapping = $mapping | Export-SPEnterpriseSearchMetadataMapping -ManagedPropertyName $managedProperty.Name
$node = $xmlMappings.ImportNode($xmlMapping.Mapping,$false)
$xmlMappings.DocumentElement.AppendChild($node) | Out-Null
}
}
else
{
$xmlMapping = Export-SPEnterpriseSearchMetadataMapping -ManagedPropertyName $managedProperty.Name -Mapping $mappings
$node = $xmlMappings.ImportNode($xmlMapping.Mapping,$false)
$xmlMappings.DocumentElement.AppendChild($node) | Out-Null
}
}
# append to Metadata
$xml.DocumentElement.AppendChild($xml.ImportNode($xmlMappings.Mappings, $true)) | Out-Null
$xml
}
}
Find example syntax of calling the advanced functions below
# get crawled properties
$crawledProperties = Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication (Get-SPEnterpriseSearchServiceApplication) | ?{$_.Name -like "ows_yourCrawledPropertyPrefix*"}
# get managed properties
$managedProperties = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication (Get-SPEnterpriseSearchServiceApplication) | ?{$_.Name -like "SomePrefix*" -or $_.Name -Like "SomeOtherManagedProperty" }
[xml]$SearchMetadata = Export-SPEnterpriseSearchMetadata -CrawledProperty $crawledProperties -ManagedProperty $managedProperties
$SearchMetadata.OuterXml | Out-File -FilePath "SearchProperties2.xml" -Encoding UTF8