Property bag is simply thw properties of web site, site collection, web application and farm. So in order to interact with the PropertyBags in PowerShell, just use the related object’s Propeties member. In the following example I used the farm object’s Properties member to edit farm level property bag. So you can modify this script to use web site, site collection or web application.
param ( [string]$WebApplicationUrl = "" ) Remove-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue Function ConfigureFarmPropertyBag([string]$propName, [string]$propValue) { $web = Get-SPFarm if (!$web.Properties.ContainsKey($propName)) { Write-Host -foregroundcolor yellow "- The '$propName' property bag couldn't be found." $web.Properties.Add($propName, $propValue); Write-Host -foregroundcolor white "- The value of the '$propName' property bag is added" } else { Write-Host -foregroundcolor yellow "- The current value of the '$propName' property bag is " $web.Properties[$propName] "." $web.Properties[$propName] = $propValue; Write-Host -foregroundcolor white "- The value of the '$propName' property bag is changed" } $web.Update(); } If (!([string]::IsNullOrEmpty($WebApplicationUrl))) { #Updating property bag Write-Host -Foregroundcolor Green "- Starting to add new parameters to the farm's property bag" ConfigureFarmPropertyBag "[PropName]" [PropValue] Write-Host -foregroundcolor Green "- Farm property bag values are updated" } Else { Throw " - Please provide the web application url parameter -WebApplicationUrl" }
2 thoughts on “Change Farm Level Property Bag using PowerShell”
Thx for good post, altought it is strange to keep a farm object in a $web variable:
$web = Get-SPFarm
Thanks.. you’re right, maybe I should change it 🙂