SharePoint Online: Change Welcome Page using PowerShell CSOM
Requirement: Set home page with PowerShell in SharePoint Online
How to change welcome page in SharePoint Online?
To set welcome page in SharePoint online, Navigate to:
PowerShell to change welcome page SharePoint Online:
Use this PowerShell script to change welcome page of a SharePoint Online site.
How to change welcome page in SharePoint Online?
To set welcome page in SharePoint online, Navigate to:
- Site Settings >> Click on "Welcome page" under Look and Feel
- Use browse or directly type any any existing page in the site to change the welcome page.
- Click OK to save your changed.
PowerShell to change welcome page SharePoint Online:
Use this PowerShell script to change welcome page of a SharePoint Online site.
#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 Variables for Site URL $SiteURL= "https://crescent.sharepoint.com/sites/sales/" $WelcomePage="SitePages/Default.aspx" #Relative path to site #Setup Credentials to connect $Cred = Get-Credential $Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password) Try { #Setup the context $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL) $Ctx.Credentials = $Cred #Set welcome page in SharePoint online $Ctx.web.RootFolder.WelcomePage =$WelcomePage $Ctx.web.RootFolder.Update() $ctx.ExecuteQuery() Write-host -f Green "Welcome page updated!" } Catch { write-host -f Red "Error setting welcome page!" $_.Exception.Message }
This worked great! I spent hours trying to figure out how to fix this problem, THANK YOU!!!
ReplyDelete