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, sleek, Responsive, easy to author, and support rich multimedia content. Creating modern pages can be done through the SharePoint user interface, but it can also be done using PowerShell. In this guide, we will walk through the steps of creating a modern page in SharePoint Online using PowerShell.

To create a modern site page, follow the below steps:

  1. Log in to your SharePoint Online site >> Click on “Settings” gear >> Click on “Site contents” from the menu.
  2. 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 on the home page. add modern page sharepoint online
  3. 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 a name, set the content of the page by adding text, images, videos, etc.
  4. Click on Publish to create the page.
Make sure you have “Site Pages” feature activated  under site features on your SharePoint Online site!

While creating a page in SharePoint is simple and straightforward, PowerShell is a powerful way to automate the process of creating pages and increase productivity.

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 = "https://crescent.sharepoint.com/sites/Intranet"
 
#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
$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

In conclusion, creating a modern page in SharePoint Online using PowerShell is a powerful way to automate the process of creating pages and increase productivity can save you a lot of time and effort. By utilizing the PnP PowerShell Add-PnPPage cmdlet, you can easily create modern pages with just a few lines of code. Additionally, once the modern page is created, it can be easily customized and tailored to fit the specific needs of your organization.

You can also create a page from saved page templates: How to Create a new page from Template in SharePoint Online?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *