Been fiddling with some script to ADD a value to the PropertyBag for a SharePoint site within Office365.
There’s a great post (and script) on the Microsoft site – for READING all properties :
How to read all property bags in a SharePoint Online Site Collection
But, for adding a new key, I had to fiddle & find an answer.
This post also – mentions the issue with “persisting” values :
Add and Retrieve property bag by CSOM (thanks !!)
NB. This code (PowerShell) will only ADD a key/value – if not already in place. (You’ll need to change slightly – to UPDATE the value)
$rootWeb = $spoCtx.Web
$spoCtx.Load($rootWeb);
$spoCtx.ExecuteQuery();
$allProps = $rootWeb.AllProperties;
$spoCtx.Load($allProps);
$spoCtx.ExecuteQuery();
# DOESN’T WORK !!
# $allProps.FieldValues.Add(‘KEY’, $value);
$rootWeb.AllProperties[‘KEY’] = $value;
$rootWeb.Update();
$spoCtx.ExecuteQuery();
That’s not TOO tricky in the end – just needed some fiddley syntax to make it work – especially the POWERSHELL bit…
Hope that helps you – it was a battle for me.
🙂