Allow custom scripts in SharePoint online site
This sample script shows how to allow use of custom scripts in SharePoint online at site level
Summary
This sample script shows how to allow use of custom scripts in SharePoint online at site level.
Scenario inspired from this blog post: Allow use of custom scripts in SharePoint Online using PowerShell
# SharePoint online admin center URL
$adminCenterUrl = "https://contoso-admin.sharepoint.com/"
# SharePoint online site URL
$siteUrl = Read-Host -Prompt "Enter your SharePoint site URL (e.g https://contoso.sharepoint.com/sites/SPConnect)"
# Connect to SharePoint online admin center
Connect-SPOService -Url $adminCenterUrl
# Allow custom scripts on SharePoint online site
Set-SPOSite $siteUrl -DenyAddAndCustomizePages 0
# Disconnect SharePoint online connection
Disconnect-SPOService
# SharePoint online site URL
$siteUrl = Read-Host -Prompt "Enter your SharePoint site URL (e.g https://contoso.sharepoint.com/sites/SPConnect)"
# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive
# Allow custom scripts on SharePoint online site
Set-PnPSite -NoScriptSite $false
# Disconnect SharePoint online connection
Disconnect-PnPOnline
# SharePoint online site URL
$siteUrl = Read-Host -Prompt "Enter your SharePoint site URL (e.g https://contoso.sharepoint.com/sites/SPConnect)"
# Get Credentials to connect
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
m365 login
}
# Allow custom scripts on SharePoint online site collection
m365 spo site set --url $siteUrl --noScriptSite $false
# Disconnect CLI for Microsoft connection
m365 logout
Contributors
| Author(s) |
|---|
| Ganesh Sanap |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
Tool documentation & references
- Introduction to the SharePoint Online Management Shell
Check out the SPO Management Shell documentation site to get started and for the reference to the cmdlets.
- Want to learn more about PnP PowerShell and the cmdlets
Check out the PnP PowerShell site to get started and for the reference to the cmdlets.
- Want to learn more about CLI for Microsoft 365 and the commands
Check out the CLI for Microsoft 365 site to get started and for the reference to the commands.