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 and adds the News web part and document library.

#Config Variable
$SiteURL = ""
#Connect to PpP Online
Connect-PnPOnline -Url $SiteURL -Interactive # -Credentials (Get-Credential)
#Create new page
$Page = Add-PnPPage -Name "News" -LayoutType Article

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

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

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

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

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

#Publish the page

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

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published.