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 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
  • 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 in it.
#Config Variable
$SiteURL = ""
#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
This creates a news page in full width as below (which is presently not possible through UI!):
sharepoint online create modern page powershell

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.