Create a Modern Page in SharePoint Online using PowerShell

Requirement: Create Modern Page in SharePoint Online using PowerShell

How to Create a Modern Page in SharePoint Online?

Modern site pages are fast, Responsive, easy to author and support rich multimedia content. To create a modern site page, follow the below steps:

  • Logon to your SharePoint Online site >> Click on “Settings” gear >> Click on “Site contents” from the menu.
  • Now, open the “Site Pages” library on the site contents page >> Click on “New” >> Site Page. You can also use the New >> Page from the toolbar in the home page.
    add modern page sharepoint online
  • Select the template and click on the “Create page” button at the bottom of the screen. This opens a new page in edit mode,  provide the name, set the content of the page, click Save and publish to create the page.
Make sure you have “Site Pages” feature activated  under site features on your SharePoint Online site!

SharePoint Online: Create Modern Page using PowerShell

This PowerShell script creates a modern page in a given communication site, adds the News web part and document library to it.

#Config Variable
$SiteURL = "https://crescent.sharepoint.com/sites/Intranet"
 
#Connect to PpP Online
Connect-PnPOnline -Url $SiteURL -UseWebLogin # -Credentials (Get-Credential)
 
#Create new page
$Page = Add-PnPClientSidePage -Name "News" -LayoutType Article

#Set Page properties
Set-PnPClientSidePage -Identity $Page -Title "News" -CommentsEnabled:$False -HeaderType Default

#Add Section to the Page
Add-PnPClientSidePageSection -Page $Page -SectionTemplate OneColumn 

#Add Text to Page
Add-PnPClientSideText -Page $Page -Text "Welcome To News Portal" -Section 1 -Column 1

#Add News web part to the section
Add-PnPClientSideWebPart -Page $Page -DefaultWebPartType News -Section 1 -Column 1

#Add List to Page
Add-PnPClientSideWebPart -Page $Page -DefaultWebPartType List -Section 1 -Column 1 -WebPartProperties @{ selectedListId = "21b99d39-834f-4991-b5f9-bd095fa0633c"} 

#Publish the page
$Page.Publish()

This creates a news page in full width as below (which is presently not possible through UI!):

sharepoint online create modern page powershell

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

Leave a Reply