Thursday, October 17, 2013

Simple powershell to set key/value pair in the web application properties

-Don't forget to add the snap in if not using the sharepoint ps console.

function SetPropertyBag ($webAppUrl, $key, $value) {

    $spwebApp=Get-SPWebApplication -Identity $webAppUrl
    Write $spwebApp

    if($spwebApp.AllProperties.ContainsKey($key) -eq $False)
    {
        $spwebApp.AllProperties.Add($key,$value);      
    }
    else
    {$spwebApp.AllProperties[$key]=$value; }

    Write-Host -foregroundcolor Green "value set in "  $key  " = "  $spwebApp.AllProperties[$key]  

    }

$webAppUrl= Read-Host 'Enter the web application url';

$keystring= Read-Host 'Enter the key string';
$valuestring= Read-Host 'Enter the value string';
SetPropertyBag $webAppUrl $keystring $valuestring;

No comments:

Post a Comment