In this article, we will review the case when the "Upload failed "Add and customize pages" permission denied" error occurs on SharePoint Site restoration or copying. This error can be found on the summary page of the completed operation (Operation Details page -> Summary Information) and the log files of the Restore SharePoint Sites or Copy SharePoint Sites operations.
Cause
This happens because the "Custom script" option is set to "Blocked" for the whole SharePoint Site collection in the Settings of the SharePoint admin center. This setting restricts users from creating custom scripts, custom pages, solutions, etc. Thus, when this option is set to "Blocked", the account you are using to perform site restore or copy, G.A. Suite cannot restore/copy solutions, custom views, forms, etc.
Starting from June 2024, this setting is set to "Blocked" by default for all users and all sites in your SharePoint Site collection.
If you open your PWA -> Site Settings -> Site Permissions -> Check Permissions (select the G.A. Suite connection account) -> Check Now, you will see that the permission "Add and customize pages" is denied.
When this feature is "Blocked", G.A. Suite will not be able to restore/copy Site Templetaes (Solutions), all aspx files, custom forms and views, etc.
For more details, please refer to the Microsoft Documentation: Features affected when custom script is blocked.
Solution
Solution 1
Before restoring/copying SharePoint Sites, the Tenant Administrator of the SharePoint Site Collection must set the "Custom script" setting to "Allowed" for restoration/copy to be completed successfully.
For this, the Tenant Administrator should navigate to the SharePoint admin center -> Active Sites -> Select the site in question -> Open the Settings page -> Click Edit under the "Custom script" setting.
Select "Allowed" and save the changes.
Please note: When you set the custom scripts setting to "Allowed", it will automatically switch back to "Blocked" within 24 hours. So, it is very important to set it to "Allowed" again if the restoration/copy of SharePoint Sites using G.A. Suite is still in progress.
Solution 2
Alternatively, the Tenant Administrator can provide the following parameter in the PowerShell script to extend the period of this setting. However, Microsoft will disable this option in November 2024.
Please note: To get started using PowerShell in SharePoint Online, you need to install the SharePoint Online Management Shell and connect to SharePoint Online. Please refer to this article for more details.
Please note: The URLs below serve as examples; you need to change them to the URL of the target SharePoint Site selected for restoration/copy.
To connect to the Admin site of the tenant:
Connect-SPOService -url https://demotenant-admin.sharepoint.com
To check the status of the setting:
Get-SPOSite -Identity https://demotenant.sharepoint.com/sites/testpwa | Select DenyAddAndCustomizePages
To change the settings to "Allowed":
Set-SPOSite -Identity https://demotenant.sharepoint.com/sites/testpwa -DenyAddAndCustomizePages $false
To change the setting to "Allowed" for more than 24 hours":
Set-SPOTenant -DelayDenyAddAndCustomizePagesEnforcement $True
To set the "Custom script" setting to "Blocked" again after the restore/copy is over:
Set-SPOSite -Identity https://demotenant.sharepoint.com/sites/testpwa -DenyAddAndCustomizePages $true