A project lead asked me for one thing: “Save site as template” on our classic SPGuidesClassic team site. The link wasn’t there, because custom script is blocked by default. To enable custom script on a SharePoint Online site, you set it to Allowed in the admin center or with PowerShell.
In this tutorial, we’ll enable custom script in SharePoint Online for that one site: check the setting, allow it with Set-SPOSite or PnP PowerShell, confirm the features that come back, find every allowed site, and block it again.
Here’s what we’re building: the site’s Custom scripts setting switched from Blocked to Allowed.

Everything below ran on 10/25/2026 against a demo site, never a production one. It’s a short, deliberate window, not a permanent change.
Before You Start
Custom script means users can add their own JavaScript or server-side pages to a site. Anyone with the Add and Customize Pages permission (site owners have it) could then add any script, and admins can’t audit or block it afterward. That’s why Microsoft blocks it.
You need the SharePoint Administrator role in Microsoft 365. Here’s the setup I used:
| Item | Value | Notes |
|---|---|---|
| Site | /sites/SPGuidesClassic | Team site (classic experience), template STS#0 |
| PowerShell 7 | 7.6.7 | SharePoint Online Management Shell + PnP.PowerShell 3.3.0 |
| Windows PowerShell | 5.1 | PnP.PowerShell 1.12.0 for the block-again step |
| Starting state | Blocked | DenyAddAndCustomizePages = Enabled |
With custom script blocked, the classic Site Settings page is thin. Web Designer Galleries shows only Site columns and Site content types, and there’s no Save site as template:

Step 1: Check the Site’s Custom Script Setting
First, we’ll see where the site stands in the SharePoint admin center.
- Open the SharePoint admin center and go to Sites > Active sites.
- Search for the site and select it (not the link) to open its panel.
- Open the Settings tab and find Custom scripts.

Checkpoint: Custom scripts shows Blocked with an Edit link next to it.
Step 2: Allow Custom Script in the Admin Center
If you prefer clicks, the change is right there.
- Select Edit next to Custom scripts.
- Under Custom scripts setting, select Allowed.
- Select Save.

Read the yellow note: the setting automatically switches back to Blocked within 24 hours. I closed this pane without saving and made the change with PowerShell instead, so I can show the exact values.
Step 3: Enable Custom Script with PowerShell (Set-SPOSite)
The PowerShell switch is -DenyAddAndCustomizePages. It denies the Add and Customize Pages right, so $false means custom script is allowed. In PowerShell 7, import the module first:
Import-Module Microsoft.Online.SharePoint.PowerShell
Connect-SPOService -Url "https://spguides-admin.sharepoint.com"
$siteUrl = "https://spguides.sharepoint.com/sites/SPGuidesClassic"
# Before: Enabled = custom script is blocked
Get-SPOSite -Identity $siteUrl | Format-List Url, DenyAddAndCustomizePages
# Allow custom script on this one site
Set-SPOSite -Identity $siteUrl -DenyAddAndCustomizePages $false
# After: Disabled = custom script is allowed
Get-SPOSite -Identity $siteUrl | Format-List Url, DenyAddAndCustomizePages

Checkpoint: The first Get-SPOSite shows Enabled (blocked) and the second shows Disabled (allowed). It took effect right away, with no wait.
Microsoft’s docs write the same thing as -DenyAddAndCustomizePages 0. If Connect-SPOService fails, see Connect-SPOService is not recognized or the tenant administration site error.
Test the Change
Refresh the classic Site Settings page. Web Designer Galleries now lists Web parts, List templates, Master pages, Themes, Solutions and Composed looks, and Site Actions has Save site as template:

That matches Microsoft’s list of what goes away while custom script is blocked:
| Feature | While blocked |
|---|---|
| Save site / list / library as template | Removed from settings |
| Theme Gallery, Help Settings, Solution Gallery | Removed from Site Settings |
| Script Editor, Content Editor, Embed, HTML Form web parts | Unavailable |
| .aspx, .master, .ascx, .swf and similar files | Can’t be uploaded or opened |
| Custom actions, Design Manager, master pages | Access denied for new ones |
Things created while custom script was allowed keep working after it’s blocked again. See why Save list as template is missing for the list version of this problem.
Step 4: Find Every Site That Allows Custom Script
In Active sites, open the view menu (it says All sites) and pick Custom script allowed sites. You can also add the Custom script column to any view.

For a script, use PnP PowerShell from the admin URL. My first filter returned a pile of RedirectSite#0 sites, left over from site URL renames, which also report Disabled. Skip them:
Connect-PnPOnline -Url "https://spguides-admin.sharepoint.com" -ClientId "<your-app-client-id>" -DeviceLogin -PersistLogin
# Which sites allow custom script right now? (redirect sites skipped)
Get-PnPTenantSite |
Where-Object { $_.DenyAddAndCustomizePages -eq "Disabled" -and $_.Template -notlike "RedirectSite*" } |
Format-Table Url, Template, DenyAddAndCustomizePages -AutoSize

Checkpoint: Only SPGuidesClassic (STS#0) comes back with Disabled.
Step 5: Use PnP PowerShell Instead
Already on PnP? Set-PnPSite -NoScriptSite $false does the same job on the connected site. New to it? Start with connecting to SharePoint Online with PowerShell.
Connect-PnPOnline -Url "https://spguides.sharepoint.com/sites/SPGuidesClassic" -ClientId "<your-app-client-id>" -DeviceLogin -PersistLogin
# Allow custom script on the connected site
Set-PnPSite -NoScriptSite $false
# Check it from the admin site (Get-PnPTenantSite needs the -admin URL)
Connect-PnPOnline -Url "https://spguides-admin.sharepoint.com" -ClientId "<your-app-client-id>" -DeviceLogin -PersistLogin
Get-PnPTenantSite -Identity "https://spguides.sharepoint.com/sites/SPGuidesClassic" | Select-Object Url, DenyAddAndCustomizePages

Note the second connection. Get-PnPTenantSite on a site connection failed with “We do not support automatically switching context to the tenant administration site”. Connect to the -admin URL first.
Step 6: Block Custom Script Again
When the template is saved, put the lock back. With the SPO module it’s one line:
Set-SPOSite -Identity $siteUrl -DenyAddAndCustomizePages $true
I did it in Windows PowerShell 5.1 to test the older stack. PnP.PowerShell 3.x won’t load there, so use 1.12.0, which also needs -Tenant. If the cmdlets aren’t found, see Connect-PnPOnline is not recognized.
Import-Module PnP.PowerShell -RequiredVersion 1.12.0
Connect-PnPOnline -Url "https://spguides.sharepoint.com/sites/SPGuidesClassic" -ClientId "<your-app-client-id>" -Tenant "spguides.onmicrosoft.com" -DeviceLogin
"PowerShell $($PSVersionTable.PSVersion) / PnP.PowerShell $((Get-Module PnP.PowerShell).Version)"
# Block custom script again when you're done
Set-PnPSite -NoScriptSite $true
# Can the current user still add and customize pages?
$web = Get-PnPWeb -Includes EffectiveBasePermissions
"AddAndCustomizePages allowed: " + $web.EffectiveBasePermissions.Has([Microsoft.SharePoint.Client.PermissionKind]::AddAndCustomizePages)

Checkpoint: AddAndCustomizePages allowed: False. Even the site owner loses that right while the site is blocked, and Get-SPOSite shows Enabled again.
Make It Production-Ready
- Plan the work inside 24 hours. Microsoft says allowed sites switch back to Not allowed within 24 hours, and there’s no permanent per-site allow. Have the template or web part work ready first.
- OneDrive is out. You can’t allow custom script on a user’s OneDrive.
- Modern sites stay modern. Modern team and communication sites are blocked by default; SPFx web parts with requiresCustomScript set to true disappear while blocked.
- Property bag only?
Set-SPOTenant -AllowWebPropertyBagUpdateWhenDenyAddAndCustomizePagesIsEnabled $truelets you update it without allowing script. - Want a permanent block? Microsoft points to Baseline security mode for blocking new custom scripts everywhere.
Troubleshooting
- “No valid OAuth 2.0 authentication session exists”: my cached sign-in had expired in both 7 and 5.1. The next cmdlet then said “No connection available”. Run Connect-SPOService again.
- Get-SPOSite isn’t found in PowerShell 7: run
Import-Module Microsoft.Online.SharePoint.PowerShell. Windows PowerShell 5.1 auto-loads it from the Management Shell install. - Get-PnPTenantSite fails on a site connection: reconnect to the -admin URL.
- The setting went back to Blocked: that’s the 24-hour override working as designed. Allow it again.
- Locked site: on ReadOnly or NoAccess sites the change doesn’t show, and it turns to Not allowed when the site is unlocked.
Where to Take It Next
Need script on modern pages? Build a modern Script Editor web part with SPFx instead of allowing custom script. For branding, add a custom theme in SharePoint.
While you’re in the admin center, review the SharePoint sharing settings in the admin center. More admin guides are in the SharePoint tutorials hub.
Working on classic sites and admin scripts? These are worth a look next:
While you’re in the SharePoint admin center, it’s worth reviewing who can share content outside your organization. My walkthrough of the sharing settings in the SharePoint admin center covers each external sharing level and the default link settings.
Frequently Asked Questions
How do I enable custom script in SharePoint Online with PowerShell?
Connect with Connect-SPOService to your admin URL, then run Set-SPOSite -Identity -DenyAddAndCustomizePages $false. Get-SPOSite should then show DenyAddAndCustomizePages as Disabled, which means allowed.
Why does custom script go back to Blocked after a day?
By design. Microsoft’s custom script guidance says changes that allow custom scripts are overridden to Not allowed within 24 hours, so do the work inside that window.
What does DenyAddAndCustomizePages do?
The Set-SPOSite reference says it determines whether the Add And Customize Pages right is denied on the site. True (Enabled) blocks custom script; False (Disabled) allows it.
Can I enable custom script on OneDrive or for all sites at once?
No for OneDrive: it can’t be allowed on a user’s OneDrive. For SharePoint, you allow it per site, and each change reverts within 24 hours.
Is it safe to allow custom script?
Only briefly. Anyone with Add and Customize Pages permission can add any script, and you can’t audit it afterward. Allow it for the task, then block it again.

Hey! I’m Bijay Kumar, founder of SPGuides.com and a Microsoft Business Applications MVP (Power Automate, Power Apps). I launched this site in 2020 because I truly enjoy working with SharePoint, Power Platform, and SharePoint Framework (SPFx), and wanted to share that passion through step-by-step tutorials, guides, and training videos. My mission is to help you learn these technologies so you can utilize SharePoint, enhance productivity, and potentially build business solutions along the way.