Provision

Add Page template to Site

This sample script shows how to add a page template to a SharePoint Online site collection

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.

Example Screenshot

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
powershell
<# .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

Contributors

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.

Tool documentation & references

Keep exploring