Enable Disable Custom Scripting Using SharePoint Management Shell

Introduction

With the latest version of SPO management shell, it is now easy to enable custom scripting on SharePoint online. Usually, this is needed when we are migrating the content from On-prem (2007/2010/2013/2016, etc) on SharePoint online as it needs some features to be migrated (like wiki, web parts, etc). Please note that when enabling custom scripting there could be potential impacts like

  • Overutilization of resources could impact performance
  • Access to resources that are more than intended

Also, you can’t audit where the custom script is injected. Please refer to references section, to understand the potential effects of custom scripting. As a workaround, MSFT recommends SharePoint framework for page customization in SharePoint online.

Steps

To get the custom scripting enabled you to need to have latest SharePoint management shell (16.0.22111.12000) installed. To install the latest SPO Management shell please refer to the references section.

Enable Disable Custom Scripting using SharePoint Management Shell

You need to have minimal of SharePoint admin / Global Admin rights.

Step 1

Connect to your org tenant,

Connect-sposervice -url “https://yourorg-admin.sharepoint.com”

To get the full details of the site, you can use below command

Get-SPOSite -Identity <siteURL> -Detailed |fl

Step 2

To enable custom scripting, DenyAddAndCustomizePages needs to be disabled. Please replace site URL with your required value.

Set-SPOSite <SiteURL> -DenyAddAndCustomizePages 0

Step 3

Check the status. Here I have selected only to show ‘DenyAddCustomizePages’ property.

Get-SPOSite -Identity <SiteURL> -Detailed|select DenyAddAndCustomizePages

Enable Disable Custom Scripting using SharePoint Management Shell

Step 4

To disable custom scripting, DenyAddAndCustomizePages needs to be enabled.

Set-SPOSite <SiteURL> -DenyAddAndCustomizePages 1

Enable Disable Custom Scripting using SharePoint Management Shell

Step 5

To check the status, try using Get-SPO site again.

Enable Disable Custom Scripting using SharePoint Management Shell

Conclusion

In this way, you can enable and disable custom scripting using latest version of SharePoint Online Management Shell easily.

References