Do you want to enable the custom script in SharePoint Online? In this tutorial, I will show you how to enable custom script in SharePoint Online using PnP PowerShell.
Why Enable Custom Script in SharePoint Online?
Let me show you, first of all, why we need to enable custom script in SharePoint Online.
In SharePoint Online modern sites, custom script is disabled by default because custom scripts can execute code with elevated permissions. Below are the things that are not possible when the custom script is disabled.
- The script editor web part and content editor web part are not available on the SharePoint Online site.
- Save list as template option will be disabled in the SharePoint Online list (Option will be hidden from the SharePoint list settings page)
- Files containing scripts will be disabled from uploading to the SharePoint site, etc.
To enable the custom script in a SharePoint Online site, you need to enable it in both places.
- Enable at the SharePoint Online admin center
- Enable at the SharePoint Online site level
Enable Custom Script in SharePoint Online Admin Center
Follow the below steps to enable custom scripts in the SharePoint Online admin center.
- Open the classic SharePoint Online tenant settings page (https://<tenantname>-admin.sharepoint.com/_layouts/15/online/TenantSettings.aspx)
- Alternatively, you can open the SharePoint Online admin center (E.g., https://szg52.sharepoint.com/), navigate to Settings, and click on the “classic settings page” link.
- Here, navigate to the “Custom Script” section and choose the “Allow users to run custom script on self-service created sites” radio button like in the screenshot below:

Once this is done, you can enable the custom scripts at the SharePoint site level.
Read Get All Lists and Libraries from SharePoint Online Site using PnP PowerShell
Enable Custom Script in SharePoint Online Site using Browser
Now, follow the below steps to enable the custom script in the SharePoint Online site using the browser.
- Open the SharePoint Online admin center, then click on Sites -> “Active sites” from the left navigation. This will display all the SharePoint online sites.
- Select the particular SharePoint Online site for which you want to enable custom scripts, click on Settings, and then click on Edit in the Custom Scripts section like below:

- Then, on the “Custom scripts” page, choose “Allowed” in the “Custom scripts setting” like the screenshot below.

This is how to enable custom scripts in a SharePoint Online modern site from the browser itself.
Check out Delete and Recover a SharePoint Online Site Using PowerShell and PnP PowerShell
Enable Custom Script in SharePoint Online Site using PnP PowerShell
I will show you now how to enable custom script in SharePoint Online site using PnP PowerShell.
Below is the complete PowerShell script.
Connect-PnPOnline -Url "https://szg52.sharepoint.com/sites/PowerPlatformFAQs" -Interactive
# Enable Custom Script on the specified site
Set-PnPTenantSite -Identity $siteUrl -DenyAddAndCustomizePages:$false
# Verify Custom Script setting
$site = Get-PnPTenantSite -Identity $siteUrl
$site.DenyAddAndCustomizePagesTo enable custom scripts on a specific site collection, you can use the Set-PnPTenantSite PnP PowerShell cmdlet. Here, you need to pass the parameter below:
-DenyAddAndCustomizePages:$falseAfter enabling custom scripts, you can verify that the setting has been applied correctly by running the following command:
$site = Get-PnPTenantSite -Identity $siteUrl
$site.DenyAddAndCustomizePagesI executed the above script using VS code, and you can see the output in the screenshot below:

This is how to enable the custom script in a SharePoint Online site using PnP PowerShell.
Here is another script you can also write using PnP PowerShell to enable custom scripts using PnP PowerShell.
Connect-PnPOnline -Url "https://szg52.sharepoint.com/sites/PowerPlatformFAQs" -Interactive
# Enable Custom Script on the specified site
Set-PnPTenantSite -Identity $siteUrl -NoScriptSite:$false
# Verify Custom Script setting
$site = Get-PnPTenantSite -Identity $siteUrl
$site.NoScriptSiteBoth methods should work fine.
In this tutorial, I have explained how to enable custom scripts for a SharePoint Online site using PnP PowerShell. Do let me know in the comments below if you face any issues while executing the script.
You may also like:
- Create a List in SharePoint Online using PowerShell or PnP PowerShell
- Delete All Items from a SharePoint List using PnP PowerShell
- Import Data from Excel to SharePoint List using PnP PowerShell
- Check if a SharePoint Site Exists using PnP PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.