Question

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()
Était-ce utile?

La solution

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();
}

Autres conseils

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

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();
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top