0

I'm trying below code to add File to Site Pages -

Add-PnPFile -Path 'C:\Temp\myfile.aspx' -Folder "SitePages" but getting "Access denied" .

I have checked permissions for my user under https://acme.sharepoint.com/sites/my-site/_layouts/15/user.aspx and found that my user gets the "Deny Add and Customize Pages" message, which probably explains why I'm not allowed to run the Add-PnPFile command.

Why I am getting the Deny Add and Customize Pages message is what's puzzling me, though.

I've created a permission level called admin permissions in which every permission (including Add and Customize Pages) is checked, and created a group admins which use that permission level. I've added myself to that group, and made sure I'm not a member of any other groups (i.e. "Owners", "Members", "Visitors") on that site.

So why do I still get the "Access denied" error message when running Add-PnPFile? In my (powershell) script I've also added Set-SPOSite -Identity <path/to/site> -DenyAddAndCustomizePages $false but still no luck.

Any help in debugging this will be appreciated.

2
  • Are you a site collection administrator for this? Or site owner? Try using these accounts once. Jun 18, 2020 at 5:28
  • @GaneshSanap, thanks for your input. I've verified that I'm indeed a site admin for the site in question.
    – kenneho
    Jun 18, 2020 at 6:00

2 Answers 2

1

Please check if you have enabled custom script at tenant level via Classic SharePoint admin center > settings > Custom Script or via this link:

https://<tenant>-admin.sharepoint.com/_layouts/15/online/TenantSettings.aspx

enter image description here

It may take up to 24 hours for this setting to take effect in your tenant. Make sure you log in as a global admin.

0
1

This command did the trick for me:

Set-SPOsite <SiteURL> -DenyAddAndCustomizePages 0

Here, 0 means it's allowed.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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