Friday, October 20, 2017

Set Modern Page as a Home Page in SharePoint Online

To Set Modern Page as a Home Page in SharePoint Online you can use the following Code from SharePoint Online PowerShell:

$siteUrl = "Your Site Url"
$password="Your Username"
$username="Your Password"
$WelcomePageUrl ="Welcome Page Url" #SitePages/WelcomePage.aspx

#Add Reference dlls
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Import-Module Sharegate




#Set Connectivity Information
write-host "Connecting to SharePoint "$siteUrl
$pwd =  convertto-securestring $password -asplaintext -force
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) 
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $pwd)
$ctx.Credentials = $credentials

#Set Welcome Page
    $web = $ctx.Web
    $rootFolder = $web.RootFolder; 
    $rootFolder.WelcomePage = $WelcomePageUrl;
    $rootFolder.Update();
    $ctx.ExecuteQuery();

No comments: