SPO Redirect all site traffic with PNP Banner META REFRESH.ps1

Want to redirect all site traffic in SharePoint Online? Not sure how? Check out this step-by-step video where we test 5 different URL redirect methods to find the best way of capturing all SharePoint Online site URL traffic and redirecting to any destination you want. Ideal for scenarios including:

  • Site collection URL renames
  • Company department rename and re-org.
  • Tenant to tenant (T2) migration
  • Classic to modern site migration
  • And more

VIDEO

CODE

# Create Banner with PNP redirect
# SPJeff - SPO Redirect all site traffic with PNP Banner META REFRESH.ps1
# NOTE - Required SPPKG deployed from https://github.com/bschlintz/spfx-message-banner/tree/master
# Connect SPO
Import-Module "PnP.PowerShell"
$siteUrl = "https://spjeffdev.sharepoint.com/sites/demo"
Connect-PnPOnline -Url $siteUrl -UseWebLogin
Get-PnPWeb
# Banner JSON
$banner = @'
{
  "message": "<meta http-equiv=\"refresh\" content=\"0;url=https://www.spjeff.com\" />",
  "textColor": "#000000",
  "backgroundColor": "#000000",
  "textFontSizePx": 0,
  "bannerHeightPx": 0,
  "visibleStartDate": null,
  "enableSetPreAllocatedTopHeight": false,
  "disableSiteAdminUI": false
}
'@
# Register Custom Action
Add-PnPCustomAction -Title "SPFx Banner PNP" -Name "SPFx Banner PNP" -Scope "Site" -Location "ClientSideExtension.ApplicationCustomizer" -ClientSideComponentId "1e2688c4-99d8-4897-8871-a9c151ccfc87" -ClientSideComponentProperties $banner -Sequence "1000"
Get-PnPCustomAction -Scope "Site"

Cheers

1 Comment

  1. Hi Jeff

    Given that you are injecting $banner into an existing SPFx solution, this solution will only work against modern sites which support SPFx, correct? If I were to access a classic page on the site then the SPFx banner would not be loaded and the redirect would not work. I need a solution that works for both Classic and Modern. I sometimes miss having the control over the IIS front ends!

    Cheers
    Andrew

Leave a Comment

Return to Top ▲Return to Top ▲