Before proceed install SharePoint PnP PowerShell Online module by running below command.
Install-Module SharePointPnPPowerShellOnline -ForceRun the below command to connect site with PnPOnline powershell.
$SiteURL = "https://MyTenant.sharepoint.com/sites/testsite" Connect-PnPOnline $SiteURLOnce you have connected the required site, run the below command to set required property value.
Set-PnPPropertyBagValue -Key "myCustomProperty" -Value "customValue"The above command works without any issue if the site setting NoScript disabled, or else you will get the below error message.
Set-PnPPropertyBagValue : Site has NoScript enabled, and setting property bag values is not supported At line:1 char:1 + Set-PnPPropertyBagValue -Key "myCustomProperty" -Value "customValue" + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (SharePointPnP.P...ropertyBagValue:SetPropertyBagValue) [Set-PnPProper tyBagValue], Exception + FullyQualifiedErrorId : NoScriptEnabled,SharePointPnP.PowerShell.Commands.SetPropertyBagValueTo disable the NoScript setting, we need to set the property DenyAddAndCustomizePages as Disabled. Run the below command to disable NoScript setting for the given site.
$site = Get-PnPTenantSite -Detailed -Url $SiteURL $site.DenyAddAndCustomizePages = 'Disabled' $site.Update() $site.Context.ExecuteQuery()-- OR -- You can also use the below command to set this value using Set-PnPTenantSite cmdlet in modern sharepoint sites.
Set-PnPTenantSite -Url $SiteURL -NoScriptSite:$falseNow run the below command to re-connect the site and set required property bag value.
Connect-PnPOnline $SiteURL Set-PnPPropertyBagValue -Key "myCustomProperty" -Value "customValue"
Get Property Bag value :
Use the below command to get the configured property value.Get-PnPPropertyBag -Key "myCustomProperty"
Remove Property Bag value :
Run the below command to delete an existing property.Remove-PnPPropertyBagValue -Key "myCustomProperty" -Force
No comments:
Post a Comment