In this recipe, we will use PowerShell to create a new publishing page and add web parts to it. This is useful in instances where a large number of these publishing pages need to be created and doing so one-by-one in the web interface would be a long and tedious process.
Follow these steps to create a web part page and add web parts using PowerShell:
Get the site with the
Get-SPWeb
Cmdlet.$web = Get-SPWeb "http://sharepoint/publishing"
Get the publishing site from the SharePoint site.
$pubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
Get the page layout from the publishing site as follows:
$layout = $pubWeb.GetAvailablePageLayouts() | Where-Object { $_.Title -eq "Blank Web Part Page" }
Create the publishing page.
$page = $pubWeb.AddPublishingPage("PowerShellPageWithWebPart.aspx", $layout)
Update the publishing page object using the following command:
$page.Update()
Set the
Title
property...