Enable Custom Script in SharePoint Online
Configure your SharePoint Online tenant to allow custom scripts for successful page migration.
Overview
When migrating SharePoint sites, custom scripts must be enabled in the target tenant for pages to migrate successfully. By default, SharePoint Online restricts custom scripts for security reasons, but this setting must be adjusted for migration operations.
Migration Requirement
Without custom script enabled, page migration will fail with a blocking error. Configure this setting before starting your migration project.
Why It's Needed
When custom script is disabled (the default setting), SharePoint blocks the migration of certain page types and web parts. This results in migration failures.
The Error You'll See
This error occurs when custom script is disabled and the migration attempts to transfer pages to the destination library.
What's Blocked
- ✗ Classic SharePoint pages
- ✗ Custom web parts
- ✗ Script-based customizations
- ✗ Content Editor web parts
What Migrates Normally
- ✓ Document libraries
- ✓ Files and folders
- ✓ Metadata and permissions
- ✓ Modern pages (usually)
How to Enable Custom Script
Option 1: SharePoint Admin Center
- 1 Access SharePoint Admin Center
Go to admin.microsoft.com → Admin centers → SharePoint
- 2 Navigate to Settings
Click Settings in the left navigation pane
- 3 Find Custom Script Settings
Scroll to find Custom Script or go to classic settings page if needed
- 4 Enable Custom Script
Select options to allow users to run custom scripts on self-service created sites and personal sites
Option 2: PowerShell (Recommended)
Use SharePoint Online Management Shell for more control:
# Connect to SharePoint Online
Connect-SPOService -Url https://yourtenant-admin.sharepoint.com
# Enable custom script for all sites
Set-SPOSite -Identity https://yourtenant.sharepoint.com/sites/targetsite ` -DenyAddAndCustomizePages $false
Replace yourtenant with your actual tenant name and targetsite with the site collection URL.
Option 3: Tenant-Wide Setting
Enable for all sites in the tenant:
Set-SPOTenant -NoScriptSite $false
Security Note
Enabling custom script tenant-wide affects all sites. Consider enabling only for specific site collections that require migration.
Propagation Delay
Changes to custom script settings may take up to 24 hours to propagate across the tenant. Plan accordingly before starting migration.
Security Considerations
Enabling custom scripts introduces potential security risks. Follow these best practices:
Limit Scope
Enable custom script only for specific site collections being migrated, not tenant-wide if possible.
Temporary Access
Consider disabling custom script after migration is complete to restore security posture.
Audit Changes
Document when custom script was enabled and for which sites. Review after migration project completion.
Post-Migration: Disable Custom Script
After migration, re-enable the security restriction:
# For specific site Set-SPOSite -Identity https://yourtenant.sharepoint.com/sites/targetsite ` -DenyAddAndCustomizePages $true # For tenant-wide Set-SPOTenant -NoScriptSite $true