10

I am trying to set some property bag values in SharePoint Online, specifically around SharePoint Designer access. The code below runs without error, but I do not see the propertybag value being updated in /_layouts/15/SharePointDesignerSettings.aspx. Is it not possible to update PropertyBag values in SharePoint Online?

$SiteUrl = "https://tenant.sharepoint.com/teams/eric"
$context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName, $credential.Password)
$web = $context.Site.RootWeb
$props =  $web.AllProperties
$props.FieldValues["allowdesigner"] = 0
$web.Update()
$context.ExecuteQuery()
12

Works for me with a couple small changes. Instead of manipulating the FieldValues object, just manipulate the AllProperties object directly. Also, set the value to a string, not an int:

web.AllProperties["allowdesigner"] = "0";

Here's the full helper method I use:

public static void AddWebProperty(ClientContext ctx, string propertyName, string propertyValue)
{
    Web web = ctx.Web;
    ctx.Load(web);
    ctx.ExecuteQuery();

    web.AllProperties[propertyName] = propertyValue;
    web.Update();            
    ctx.ExecuteQuery();
}
  • I knew I was effing something up somewhere. Adapting this to the existing PowerShell I had then set the desired properties. – Eric Alexander Feb 16 '16 at 14:34
  • 3
    You don't need to load properties. It's just unnecessary traffic. – dstarkowski Feb 16 '16 at 14:35
  • @dstarkowski I wasn't sure, and never bothered to verify. I've edited the post to remove that. Thank you. – Derek Gusoff Feb 16 '16 at 14:49
7

Derek's answer solves problem for property bag in general, but there's also Site.AllowDesigner property you could use for your specific case.

0

PFB script to update in SP online to disable all controls in Designer settings in Site Collection

$url="SC URL"

$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($url) 

$username= "Username";
$password=ConvertTo-SecureString 'Password' -AsPlainText -Force;

$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username , $password);

$ctx.Credentials = $credentials ;

$web=$ctx.site;

$ctx.load($web);

$web.AllowDesigner=0;

$web.AllowMasterPageEditing=0;

$web.AllowRevertFromTemplate=0;

$web.ShowUrlStructure=0;

$ctx.ExecuteQuery();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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