For SharePoint sites, custom script can be used to customize the look, feel, and behavior of web pages and sites according to your requirements. By default, custom script is only allowed on sites created by SharePoint admins but blocked on user-created sites. If custom script is blocked, you may see the error
Custom Scripts are not enabled when trying to restore your data.
To resolve the error, use the SharePoint Online Management Shell, a tool containing a Windows Powershell, to enable custom script for the site(s) you are trying to restore data from. Note that this process may not work for all sites.
Download the latest SharePoint Online Management Shell at https://www.microsoft.com/en-US/download/details.aspx?id=35588.
For more information on how to install and connect, see the following article from Microsoft https://learn.microsoft.com/en-us/powershell/sharepoint/sharepoint-online/connect-sharepoint-online.
Enable Custom Script
- Open the SharePoint Online Management Shell.
Connect to SharePoint Online Management Shell by running the following command:
Connect-SPOService -Url https://<your-domain>-admin.sharepoint.com
You will be prompted to sign in as an administrator for the domain.
Verify that the site you are trying to restore is in the site list by running the following command. Take note of the site you want to enable custom script for.
You should see something similar to this site list:
Check if custom script is currently enabled by running this command:
Get-SPOsite -Identity https://<your-domain>.sharepoint.com/sites/<site-name> | select DenyAddAndCustomizePages
In this example, the site work does not have custom script enabled. To enable custom script,
DenyAddAndCustomizePagesshould be disabled.
To enable custom script, run the following command to set the
DenyAddAndCustomizePagesvalue to 0 (0=disabled, 1=enabled):
Set-SPOSite https://<your-domain>.sharepoint.com/sites/<site-name> -DenyAddAndCustomizePages 0
Note that there is no output from this command.
Verify that custom script is enabled by running this command:
Get-SPOSite -Identity https://<your-domain>.sharepoint.com/sites/<site-name> | select DenyAddAndCustomizePages