Skip to content

Instantly share code, notes, and snippets.

@pkbullock
Last active July 31, 2020 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pkbullock/6637aa65e875829102e0ab95179d3a4a to your computer and use it in GitHub Desktop.
Save pkbullock/6637aa65e875829102e0ab95179d3a4a to your computer and use it in GitHub Desktop.
Set 404 Property on SharePoint site
$tenant = "<tenant>"
$site = "<site>"
$siteUrl = "https://$($tenant).sharepoint.com/sites/$($site)"
Write-Host "Setting 404 page at $($siteUrl)..."
# Connect to SharePoint Online with PnP PowerShell library
Connect-PnPOnline $siteUrl -UseWebLogin
# Disable NoScript
Write-Host " Disabling NoScript" -ForegroundColor Cyan
Set-PnPTenantSite -Url $siteUrl -NoScriptSite:$false
# Sets the value in the property bag, note: ensure you have disabled NoScript
Write-Host " Adding Property Bag Key" -ForegroundColor Cyan
Set-PnPPropertyBagValue -Key "vti_filenotfoundpage" -Value "/sites/$($site)/SitePages/Page-not-found.aspx"
# Enable NoScript
Write-Host " Enabling NoScript" -ForegroundColor Cyan
Set-PnPTenantSite -Url $siteUrl -NoScriptSite
Write-Host "Script Complete! :)" -ForegroundColor Green
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment