Add Page template to Site
Summary
This sample script shows how to add a page template to a SharePoint Online site collection using PnP PowerShell and CLI for Microsoft 365.
Implementation
- Open Visual Studio Code
- Create a new ps1 file
- Write a script as below
- Run the script like in the .Example of the Synopsis
<# .SYNOPSIS
Provision a page templates.
.DESCRIPTION
You need to have the latest version of PnP PowerShell
Provision a single page template to a SharePoint Online site collection.
.PARAMETER SiteCollection
Specifies the URL of the SharePoint Online Site Collection.
.PARAMETER PageName
Specifies the name of the new page template.
.EXAMPLE
PS> .\add_spopagetemplate.ps1 -SiteCollection "https://contoso.sharepoint.com" -PageName "Contoso Page Template"
#>
param ([Parameter(Mandatory)]$SiteCollection,[Parameter(Mandatory)]$PageName)
# Variables
$LogFileName = "add_spopagetemplates_" + $(get-date -f filedatetime) + ".txt"
#####################
Start-Transcript -Path .\logs\$LogFileName -NoClobber
Connect-PnPOnline -Url $SiteCollection -Interactive
Add-PnPPage -Name $PageName -HeaderLayoutType FullWidthImage -PromoteAs Template -Publish
Disconnect-PnPOnline
#####################
Stop-Transcript
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?
Contributors
Author(s) |
---|
@Expiscornovus |
Ganesh Sanap |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.