最近接到需求,要對一個SharePoint Online站點的site properties bag value進行更新,但是在執行下面update後,
$web.AllProperties[$propertyBagName] = $propertyBagValue;
$web.AllProperties["PropertyBagValue"] = "Value1";
$web.Update();
$Context.ExecuteQuery();
彈出下面錯誤信息:
Exception Calling "ExecuteQuery" with "0" argument(s): "Access denied. You do not have any permission to perform this action or access this resource…" ,更新value失敗。
但是當前使用的是SharePoint Online的administrator,權限足夠執行。
經過check,主要是因爲當前的Modern Site的IsNoScript的屬性值是false,阻止了使用script更新object。
要解決此問題,需要將site collection對應的屬性值進行修改。
具體方法如下:
1. 使用administrator打開SharePoint Online Management Shell;
2. 執行Connect-SPOService連接SharePoint Online,輸入SharePoint Online Admin的URL並點擊回車,在彈出的窗口中輸入administrator的用戶名和密碼登陸;
3. 此時執行下面語句查看當前情況,返回Enabled說明阻止script修改properties value
$a = get-spsite "https://sitecollection url " -Detailed
$a.DenyAddAndCustomizePages
4. 執行下面語句更改
Set-SPOsite "https://sitecollection url " -DenyAddAndCustomizePages 0
5. 更改完成,重新執行update site properties bag value的script,更新成功,問題解決。
6. 如果想要更改爲阻止script修改properties,重新執行Step4,並把對應的值“0”改成“1”運行。
感謝閱讀。