Issue Details
Last week, while working on a Team automation job, we faced an issue when trying to copy images to Style library on a SharePoint Site (with Microsoft Teams) using PnP PowerShell and got an “Access Denied” message.

The strange thing was that the account running the job had Site Collection Admin Access, so the account should be able to write data to any library in the site. It took some time to figure out the real cause of the issue and so this quick blog, where I will be listing the way to resolve it quickly. Hopefully it will save some time for anyone who is stuck.
Cause
While futher investigating, I recalled a blog that I wrote a while ago about Modern Sites and scripting not allowing updating Site property bag. The blog is located here for reference. Yeah this seems to be completely unrelated issue but thought let’s give it a crack, it could be related š
Resolution
Yes, the issue was related to the NoScript setting of Modern Sites, which don’t allow you to add scripts to SharePoint Sites. Strangely, this doesn’t also allow to add images to Style library. Weird !!
But then the resolution to the issue is quite simple as below:
1. Connect to the Site using SharePoint Management PowerShell as shown in the below command line.
Note: Know more about SharePoint Online Management shell here and download the SharePoint Online Management Shell here.
Connect-SPOService -Url https://<tenantname>-admin.sharepoint.com
Note: For connecting to SharePoint Online management shell, you will need minimum Global Administrator rights on SharePoint instance, which is different than PnP PowerShell where you could use only SharePoint Site Collection admin rights
2. Run the below script to turn off NoScript on the modern site. After sucess, try to upload images to Style library and it should work fine.
Set-SPOSite -Identity https://<SiteUrl> -DenyAddAndCustomizePages 0
So there you go, simple and easy.
Note: The above NoScript will reset automatically so the above script might have to run everytime the upload process on the site have to be done.
Leave a Reply