GitHub Icon Image
GitHub

Update SharePoint Page Banner Image

Summary

This sample script shows how to update the banner image at the top of the SharePoint online modern page using PnP PowerShell and CLI for Microsoft 365.

Scenario inspired from this blog post: Update SharePoint Page Banner Image using PnP PowerShell

Outupt Screenshot

  • PnP PowerShell
  • CLI for Microsoft 365

# SharePoint online site url
$siteUrl = "https://contoso.sharepoint.com/sites/wlive"	

# Name of the site page
$pageName = "Open-Door-Policy"

# Server relative URL of the image to use in site page header
$imageUrl = "/sites/wlive/SiteAssets/work-remotely.jpeg"

# Connect to SharePoint Online site  
Connect-PnPOnline -Url $siteUrl -Interactive

# Update site page banner image
Set-PnPPage -Identity $pageName -HeaderType Custom -ServerRelativeImageUrl $imageUrl

Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell

The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?


# SharePoint online site URL
$siteUrl = "https://contoso.sharepoint.com/sites/wlive"

# Name of the site page
$pageName = "Open-Door-Policy.aspx"

# Server relative URL of the image to use in site page header
$imageUrl = "/sites/wlive/SiteAssets/work-remotely.jpeg"

# Get Credentials to connect
$m365Status = m365 status
if ($m365Status -match "Logged Out") {
   m365 login
}

# Update site page banner image
m365 spo page header set --webUrl $siteUrl --pageName $pageName --type Custom --imageUrl $imageUrl

Check out the CLI for Microsoft 365 to learn more at: https://aka.ms/cli-m365

Important changes coming to the way you login into CLI for Microsoft 365 (effective 9th September 2024) see Changes in PnP Management Shell registration in Microsoft 365

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.

Back to top Script Samples
Generated by DocFX with Material UI