How to Create Managed Property in Sharepoint 2013 using Powershell?

In this article, we will see how to create  new managed property in Sharepoint 2013 environment. Below is the sample powershell script to achieve the same.

#Get Search Service Application
$category = Get-SPEnterpriseSearchMetadataCategory –SearchApplication $searchapp –Identity $_.Category

#Get the Crawled Property First
$cprop = Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -name $_.CrawledPropertyName -Category $category -ea silentlycontinue

#If the Crawled Property is present
if ($cprop)
{
# Check whether Managed Property already exists

$mproperty = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $_.ManagedPropertyName -ea silentlycontinue
if ($mproperty )
{
Write-Host -f green”Cannot create managed property” $_.ManagedPropertyName “because it already exists”

}
else
{
# If already not there, then create Managed Property
New-SPEnterpriseSearchMetadataManagedProperty -Name $_.ManagedPropertyName -SearchApplication $searchapp -Type $_.Type -Description $_.Description
$mproperty = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $_.ManagedPropertyName

          #Map the Managed Property with the Crawled Property
New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchapp -ManagedProperty $mproperty –                  CrawledProperty  $cprop
}

}

Hope it helps!! Happy Sharepointing 🙂

Leave a Reply

Your email address will not be published.