3

I have this PowerShell script

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

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

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

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

    }

$webAppUrl= Read-Host 'Enter the web application url';
$siteCollectionUrl= Read-Host 'Enter the site collection url';
SetPropertyBag $webAppUrl "VGSP.VIS.TicketTale.EngineJob" $siteCollectionUrl ;

It's working great on PowerShell but when i try to get the property bag value by server side code I don't find.

I also deployed the property bag settings solution and didn't find the values that I've set there either.

3 Answers 3

2
$spwebApp.Properties.Add($key,$value);
$spwebApp.Update();
3
  • Method invocation failed because [System.Collections.Hashtable] doesn't contain a method named 'Update'. At C:\Users\Alshimaa\Desktop\PropertyBagSetter.ps1:19 char:32 + $spwebApp.Properties.Update <<<< (); + CategoryInfo : InvalidOperation: (Update:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
    – mshmshcs
    Sep 9, 2012 at 13:15
  • It is actually recomanded to use AllProperties instead as Properties is only maintained for back-compatibility purposes and is obsolete! Sep 9, 2012 at 16:10
  • Thanks @c-marius, updated the answer to use AllProperties
    – eirikb
    Sep 9, 2012 at 19:07
2

Just had the same problem. Solution:

$spwebApp.Update();

The solution suggested by eirikb does not work because:

  1. The SPWebApplication object does not have a property called "AllProperties".
  2. It does have a property called "Properties" (as written by the OP), however this property does not have an Update() method.

(Note: I'm using SP2010)

0

You can set property bag value using power shell and the same can be retrievable from C# code with the help of unique Key.

Below is the link, where it had explained to set property bag value and retrieve the same. http://himanshu214.blogspot.in/2015/10/powershell-set-property-bag-to.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.