It seems like your browser didn't download the required fonts. Please revise your security settings and try again.

How to Enable Custom Script for SharePoint

  • Last updated on

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

  1. Open the SharePoint Online Management Shell. 
  2. 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.

  3. 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-SPOSite

    You should see something similar to this site list:
    SPOSiteList.png

  4. 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, DenyAddAndCustomizePages should be disabled
    checkCustomScripts.png

  5. To enable custom script, run the following command to set the DenyAddAndCustomizePages value 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.

  6. Verify that custom script is enabled by running this command:

    Get-SPOSite -Identity https://<your-domain>.sharepoint.com/sites/<site-name> | select DenyAddAndCustomizePages

    enableCustomScripts.png