Last active
August 29, 2015 14:14
-
-
Save phillipharding/f0d8a2b79c64158464b0 to your computer and use it in GitHub Desktop.
Set an PropertyBag property as Indexable (Queryable via Search)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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