SharePoint Online: How to Change Home Page using PowerShell?

Requirement: SharePoint Online Set Home Page

How to Change Home page in SharePoint Online?
The welcome page or Home page is the initial page displayed when you browse to a site. By default Home.aspx page in the Site Pages library is defined as the site welcome page. You can create new page and set as the site's welcome page. To set home page in SharePoint Online:
  • Navigate to Site Settings >> Click on "Welcome Page" link under "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 welcome page in SharePoint Online.
To get "Welcome page" link in site settings, "SharePoint Server Publishing" feature must be activated. Once its active, you'll get Welcome Page link in the Site Settings.

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
$SiteURL="https://crescent.sharepoint.com"
#Relative url of the homepage
$HomePageURL="SitePages/default.aspx"

#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
$Ctx.web.RootFolder.Update()
$Ctx.ExecuteQuery()
This PowerShell CSOM script sets home page in SharePoint Online.

PnP PowerShell to Make Document Library as home page in SharePoint Online
This time, lets set a document library as home page for a SharePoint Online site using PnP PowerShell
#Config Variables
$SiteURL = "https://crescenttech.sharepoint.com/Sales"
#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

#Set Home page
Set-PnPHomePage -RootFolderRelativeUrl $HomePageURL 
SharePoint Online: How to Change Home Page using PowerShell? SharePoint Online: How to Change Home Page using PowerShell? Reviewed by Salaudeen Rajack on February 08, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.