In the previous article, we saw How to create a Managed Property in SharePoint 2013 using PowerShell.
In this article, let us see how to Update Managed Property with various properties.
The script is as follows.
$LogTime = Get-Date -Format yyyy-MM-dd_hh-mm
$LogFile = ".UpdateManagedPropertyPatch-$LogTime.rtf"
#start-transcript $logfile
# Add SharePoint PowerShell Snapin
if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null ) {
Add-PSSnapin Microsoft.SharePoint.Powershell
}
$scriptBase = split-path $SCRIPT:MyInvocation.MyCommand.Path -parent
Set-Location $scriptBase
$OutputPath = $scriptBase + "" + "ManagedPropErrors.txt"
if (test-path $OutputPath)
{
remove-item $OutputPath
}
$csvfile = $scriptBase + "" + "EditManagedProp.csv"
Import-csv $csvfile | where {
$searchapp = Get-SPEnterpriseSearchServiceApplication
$ManagedProperty = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Identity $_.ManagedPropertyName -ea silentlycontinue
if($ManagedProperty)
{
$ManagedProperty.Searchable = $true
$ManagedProperty.Queryable = $true
$ManagedProperty.Sortable = $true
$ManagedProperty.Retrievable = $true
$ManagedProperty.Refinable = $true
$ManagedProperty.SafeForAnonymous = $true
$ManagedProperty.update()
write-host "The searchable, queryable, Sortable, Retrievable and Refinable for the managed property" $_.ManagedPropertyName "has been enabled successfully ...... Done !" -fore green
}
else
{
Write-Host -f Yellow "The specified managed property " $_.ManagedPropertyName " does not exists... Please check whether you have given valid managed property name"
$a = "The specified managed property " + $_.ManagedPropertyName + " does not exists... Please check whether you have given valid crawled property name"| out-file $OutputPath -append
}
}
#stop-transcript
Happy Coding.
Sathish Nadarajan.
Leave a comment