SharePoint Online: How to Change Home Page using PowerShell?

Requirement: Set Home Page in SharePoint Online.

How to Change the Default Home page in SharePoint Online?

The welcome page or Home page is the default page displayed when you browse to a site. By default, the Home.aspx page in the Site Pages library is defined as the site’s welcome page. You can create a new page and set it as a welcome page. To set the home page in SharePoint Online, do the following:

  • Navigate to Site Settings >> Click on the “Welcome Page” link under the “Look and Feel” group
    SharePoint Online Set Home Page
  • This takes you to the “Site Welcome Page” (/_layouts/15/AreaWelcomePage.aspx) where you can pick any existing page and set it as a welcome page or home page for your SharePoint Online site.
    sharepoint online powershell set home page

This changes the welcome page in SharePoint Online.

To get “Welcome page” link in site settings, “SharePoint Server Publishing” feature must be activated. Once it is active, you’ll get Welcome Page link in the Site Settings.

SharePoint Online: Set Modern Page as Homepage

How to make a page as homepage in SharePoint Online? In modern sites, You can change the site home page by navigating to:

  • Click on “Site Settings” gear >> Site Contents
  • Click on “Site Pages” Library >> Right-click on the target Home page, and select “Make Home Page” from the context menu.
    sharepoint online change home page to modern sites

This sets the page as the home page in SharePoint Online!

SharePoint Online: Change home page using PowerShell

Here is the PowerShell to set the page as a homepage in SharePoint Online:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Set Parameter Values
#Relative url of the homepage

#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred

#sharepoint online powershell set home page
$Ctx.web.RootFolder.WelcomePage = $HomePageURL

This PowerShell CSOM script sets the home page in SharePoint Online.

PnP PowerShell to Make Document Library as home page in SharePoint Online

This time, let’s set a document library as a home page for a SharePoint Online site using PnP PowerShell.

#Config Variables
$SiteURL = ""
#Page Relative URL to the Web
$HomePageURL = "Shared Documents/Forms/AllItems.aspx"

#Get Credentials to connect
$Cred = Get-Credential
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials $Cred

#make a document library as home page in sharepoint online
Set-PnPHomePage -RootFolderRelativeUrl $HomePageURL 

Similarly, You can set a List page as Home page by setting the $HomePageURL parameter to: $HomePageURL = “Lists/PortfolioTracker/AllItems.aspx”

Set-PnPHomePage -RootFolderRelativeUrl Shared%20Documents/Forms/AllItems.aspx

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply