SetPropertyBagValue.ps1

Script

Name

Description

Last Modified Date

Download

SetPropertyBagValue.ps1

Updates the property bag of the root web in a specified site collection

31/01/2012

None

#Script: SetPropertyBagValue.ps1
#Source: https://codemonkeysoftware.atlassian.net
param 
    (    
	$siteCollectionUrl = (Read-Host "Please enter a site collection url"),
        $name = (Read-Host "Please enter a key name"),
        $value = (Read-Host "Please enter a value")
    )
    
#region SharePoint Snappin Setup
$snapin="Microsoft.SharePoint.PowerShell"
if (get-pssnapin $snapin -ea "silentlycontinue") {
    write-host -f Green "PSsnapin $snapin is loaded"
}
else {
    if (get-pssnapin $snapin -registered -ea "silentlycontinue") {
        write-host -f Green "PSsnapin $snapin is registered"
        Add-PSSnapin $snapin
        write-host -f Green "PSsnapin $snapin is loaded"
    }
    else {
        write-host -f Red "PSSnapin $snapin not found"
    }
}
#endregion
    
[Microsoft.SharePoint.SPSite] $site = get-spsite -Limit ALL | where-object {$_.Url -ieq $siteCollectionUrl}
if($site -eq $null)
{
    Write-Host -ForegroundColor Red "Unable to find site collection"
    throw "Unable to find site collection"
}
$site.RootWeb.AllProperties[$name] = $value
$site.RootWeb.Update()

CodeMonkey Software is a division of JCHMedia www.jchmedia.com