Enable scripting in a SharePoint site collection using PowerShell

Use these snippets to turn on scripting in site collections on SharePoint online. You must be a tenant admin, and you must run the code in PowerShell. Change the variables $tenantName and $siteCollectionRelativeUrl to match your actual tenant and site name.

Allow custom scripting

# $tenantName is the tenant name - for example contoso
$tenantName = "";
# $siteCollectionRelativeUrl is the relative URL of your target site collection. # Leave empty to target the root site collection, or use /sites/sitename # Please note that you must not have a trailing slash after sitename $siteCollectionRelativeUrl = "";
############################################################# ############## NO CHANGES BELOW THIS LINE ################### ############################################################# Connect-SPOService -Url https://$tenantName-admin.sharepoint.com $Url = "https://$tenantName.sharepoint.com$siteCollectionRelativeUrl" Set-SPOSite -Identity $Url -DenyAddAndCustomizePages 0

Check the state

# $tenantName is the tenant name - for example contoso
$tenantName = "";

# $siteCollectionRelativeUrl is the relative URL of your target site collection.
# Leave empty to target the root site collection, or use /sites/sitename
# Please note that you must not have a trailing slash after sitename
$siteCollectionRelativeUrl = "";

#############################################################
############## NO CHANGES BELOW THIS LINE ################### ############################################################# Connect-SPOService -Url https://$tenantName-admin.sharepoint.com $Url = "https://$tenantName.sharepoint.com$siteCollectionRelativeUrl" Get-SPOSite -Identity $Url -Detailed | select DenyAddAndCustomizePages

This should output “Disabled” when custom scripting is allowed.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.