Skip to content

Instantly share code, notes, and snippets.

@phillipharding
Last active August 29, 2015 14:14
Show Gist options
  • Save phillipharding/f0d8a2b79c64158464b0 to your computer and use it in GitHub Desktop.
Save phillipharding/f0d8a2b79c64158464b0 to your computer and use it in GitHub Desktop.
Set an PropertyBag property as Indexable (Queryable via Search)
cls
Add-PSSnapin Microsoft.SharePoint.Powershell -ea SilentlyContinue
$w = Get-SPWeb "http://pub.pdogs.local/news"
$allProps = $w.AllProperties
$allProps.Keys | ? { $_ -match "^vti_indexedpropertykeys" } | % { "$_ = [$($allProps[$_])]" }
Write-Host
$propertyName = "MyWebTemplateID"
# indexedpropertykey must be base64 encoded value of the unicode string
$encodedPropertyName = [Convert]::ToBase64String([System.Text.Encoding]::Unicode.GetBytes($propertyName))
# set the regular web property value
$allProps[$propertyName] = "CorpNews"
# now set it as indexable
$ipPropertyName = "vti_indexedpropertykeys"
$existingIPPropertyValue = $allProps[$ipPropertyName]
if ($existingIPPropertyValue -notlike "*$encodedPropertyName*") {
# the property name is not in the indexedpropertykeys property, so add it including the terminating pipe | character
Write-Host "Setting $ipPropertyName property"
$allProps[$ipPropertyName] = "$existingIPPropertyValue$encodedPropertyName|"
}
$w.Update()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment