Set web properties

22/11/2013 15:13

#Set web properties as hashtable

$properties = New-Object hashtable

$properties.Add("property1name", "someValue");

$properties.Add("property2name", "otherValue"));

 

& $location\SetWebProperties.ps1 -webUrl $webUrl -properties $properties

 

SetWebProperties.ps1 file with param

#Adds properties (key - values)to web property bag

param($webUrl, [hashtable]$properties)

 

 

$web = Get-SPWeb $webUrl

foreach($key in $properties.Keys)

{

    if($web.Properties.ContainsKey($key))

    {

        "Changing web property '{0}' from '{1}' to '{2}'... " -f $key, $web.Properties[$key], $properties[$key]

        $web.Properties[$key] = $properties[$key]

    }

    else

    {

        "Adding web property '{0}' with value '{1}'..." -f $key, $properties[$key]

        $web.Properties.Add($key, $properties[$key])

    }

    $web.Properties.Update()

}

$web.Dispose()