Set SPEnterpriseSearchMetadataCrawledProperty

by utwolfpack at 2012-12-27 15:17:05

Does anyone know how to Set a SPEnterpriseSearchMetadataCrawledProperty to be included in index using powershell? I have approx 1000 to set on a project that I am building so as you can imagine I would really not like to set them using the Metadata Properties UI.

I was thinking something along the lines of:

Set-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication “Search Service Application” -Identity $NameofCrawledProperty –Retrievable $true

Any help would be appreciated, thanks in advance.

- Sean O.
by AlexBrassington at 2013-02-11 05:19:34
The first step is to create a crawled property, from there if you want to use it that needs to be mapped to a mapped property.

I had something similar recently and produced this:
Function Create-AndMapProperty()
param([string] $propName, [string] $managedPropName)

Write-Host “Processing $propName”

#Get the crawled property if it already exists.
$crawledproperty = $searchapp | Get-SPEnterpriseSearchMetadataCrawledProperty -Name $propName

#If it doesn’t, create it
if ($crawledproperty -eq $null)
Write-Host -ForegroundColor Yellow “Not found: $propName”
New-SPEnterpriseSearchMetadataCrawledProperty -SearchApplication $searchapp -Category $category -VariantType 31 -PropSet “00130329-0000-0130-c000-000000131346” -Name $propName -IsNameEnum $false | Out-Null
$crawledproperty = $searchapp | Get-SPEnterpriseSearchMetadataCrawledProperty -Name $propName
Write-Host -ForegroundColor Blue “$propName Created”
Write-Host -ForegroundColor Blue “$propName Found”

#Get the managed property if it already exists
$managedproperty = $searchapp | Get-SPEnterpriseSearchMetadataManagedProperty $managedPropName -ea SilentlyContinue

#If it doesn’t, create it
if ($managedproperty -eq $null)
Write-Host -ForegroundColor Blue “Not found: $managedPropName”
New-SPEnterpriseSearchMetadataManagedProperty -SearchApplication $searchapp -Name $managedPropName -Type 1 | Out-Null
$managedproperty = $searchapp | Get-SPEnterpriseSearchMetadataManagedProperty $managedPropName
Write-Host -ForegroundColor Blue “$managedPropName Created”
#Not a major issue. Some properties may already have mappings.
Write-Host -ForegroundColor Yellow “$managedPropName Found”
Write-Host “Creating mapping”
New-SPEnterpriseSearchMetadataMapping -SearchApplication $searchapp -ManagedProperty $managedproperty -CrawledProperty $crawledproperty -ea SilentlyContinue


#Setup pre-requisites. No point in including in loop or function.
$searchapp = Get-SPEnterpriseSearchServiceApplication
$category = Get-SPEnterpriseSearchMetadataCategory –Identity SharePoint -SearchApplication $searchapp

#Loop through all of the fields and process.
#Note: I’ve removed the declaration but it’s a simple list.
foreach ($property in $siteColumns)
Write-Host $property

$propName = “ows_” + $property.Replace(’ ‘,’’)
$managedPropName = $property.Replace(’ ‘,’’)

Create-AndMapProperty $propName $managedPropName

You might not want the entirety of it but it’s easier to trim a script down. The lines relating to existing mappings are ‘appendix’ code, i was building it to abort if there already was a mapping but I don’t think i ever progressed it that far/made use of it.

Edited for additional explanation and better formatting.