if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" } Function UpdateManagedPropertyMapping([string]$managedPropertyName, [string]$crawledPropertyName, $searchApp) { $managedProperty = Get-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchApp -Identity $managedPropertyName -ErrorAction SilentlyContinue Write-Host Adding/Updating managed property $managedPropertyName if($managedProperty -eq $null) { #create a new property Write-Host Creating managed property $managedPropertyName $managedProperty = New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchApp -Name $managedPropertyName -Type 1 -Queryable $true -Retrievable $true $managedProperty.Refinable = $true $managedProperty.Sortable = $true $managedProperty.Update() Write-Host Created managed property $managedPropertyName } else { Write-Host Managed property $managedPropertyName already exists } $managedPropertyMapping = Get-SPEnterpriseSearchMetadataMapping -SearchApplication $searchApp -ManagedProperty $managedProperty if($managedPropertyMapping) { #remove mapping Write-Host Removing existing mapping Remove-SPEnterpriseSearchMetadataMapping -Identity $managedPropertyMapping -Confirm:$false } Write-Host Mapping property $crawledPropertyName to $managedPropertyName $crawledProperty = Get-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchApp -Name $crawledPropertyName $managedPropertyMapping = New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchApp -ManagedProperty $managedProperty -CrawledProperty $crawledProperty Write-Host Finished adding/updating managed property $managedPropertyName } $searchApp = Get-SPEnterpriseSearchServiceApplication UpdateManagedPropertyMapping FFBoKAuthor ows_Author0 $searchApp UpdateManagedPropertyMapping FFBoKPublicationYear ows_CategoryLevel1 $searchApp UpdateManagedPropertyMapping FFBoKCategory1 ows_CategoryLevel1 $searchApp
I hope this script proves useful to someone.
No comments:
Post a Comment