Create Publishing Page In SharePoint 2016 Using PowerShell

Publishing Pages can be used to create pages, which serve as the Web part pages, welcome pages and so on. We can use out of the box as well as custom layouts to define the page. However in order to create the Publishing Page, we must make sure that the publishing feature is enabled in the site collection as well as the site level.


Though we can create it out of the box, let’s see how we can create it, using PowerShell. Spin up SharePoint 2016 Management Shell.


We will be using the script, given below to create the Publishing Page, using blank Web part page layout.

  1. $PageLayoutUrl = "/_catalogs/masterpage/BlankWebPartPage.aspx"  
  2. $PageName = "Test.aspx"  
  3.  
  4. #  
  5. Get site object and create publishing site object  
  6. $SPSite = Get - SPSite("http://sharepoint2016")  
  7. $PublishingSite = New - Object Microsoft.SharePoint.Publishing.PublishingSite($SPSite)  
  8.  
  9. # Get web object and create publishing web object  
  10. $SPWeb = Get - SPWeb "http://sharepoint2016"  
  11. $PublishingWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($SPWeb)  
  12. $LayoutsColl = $PublishingSite.GetPageLayouts($False)  
  13.  
  14.  
  15. # Get the page layout object and create Publishing Page based on it  
  16. $SPPageLayout = $LayoutsColl[$PageLayoutUrl]  
  17. $Page = $PublishingWeb.AddPublishingPage("WelcomePage.aspx", $SPPageLayout)  
  18. $Page.Title = "Welcome"  
  19. $Page.Update();  
  20. $Page.CheckIn("Page Created")  
  21. $Page.ListItem.File.Publish("Page Checked in and Publishing Completed")   

 

The script has run to completion. Now, let’s head over to the pages library. We can see the Publishing Page by the title ‘WelcomePage’ listed in the pages library.


Summary

Thus, we saw how to create a Publishing Page in SharePoint Server 2016, using PowerShell.

Ebook Download
View all
Learn
View all