How to Enable Custom Script for SharePoint
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.
You do not need to enable custom script for all sites. A best practice is to allow custom script only for the specific site(s) you are restoring, and then disable custom script after the restore is complete. Note: This change will not apply retroactively to sites created prior to this point.
Before you enable custom script, review the security considerations from Microsoft here https://learn.microsoft.com/en-us/sharepoint/security-considerations-of-allowing-custom-script.
Prerequisite
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.comYou 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.
Get-SPOSiteYou 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 DenyAddAndCustomizePagesIn 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 0Note 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
Contact Us
Barracuda Campus
Barracuda Support