SharePoint Online: Apply Theme using PnP Provisioning Template PowerShell

Requirement: Set Theme in SharePoint Online Site using PnP PowerShell Provisioning Template.

How to Change the Site Theme in SharePoint Online using PnP Provisioning Template?

In order to apply a theme to a SharePoint Online site using a PnP Provisioning Template and PowerShell, you will need to complete the following steps:

Step 1: Create a Provisioning Template Schema XML for the Theme

Go to the PnP Provisioning Schema repository in GitHub and build your provisioning template. https://github.com/SharePoint/PnP-Provisioning-Schema, You can also get the template from an existing site using the Get-PnPSiteTemplate cmdlet. Here is mine:

<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="https://schemas.dev.office.com/PnP/2019/03/ProvisioningSchema">
  <pnp:Preferences Generator="OfficeDevPnP.Core, Version=3.9.1905.0, Culture=neutral, PublicKeyToken=null" />
  <pnp:Templates ID="CONTAINER-TEMPLATE-a170b11a-d4d3-486f-b191-946ff2acaec3">
    <pnp:ProvisioningTemplate ID="TEMPLATE-a170b11a-d4d3-486f-b191-946ff2acaec3" Version="1" BaseSiteTemplate="SITEPAGEPUBLISHING#0" Scope="RootSite">
      <pnp:Theme Name="Orange" IsInverted="false" />
    </pnp:ProvisioningTemplate>
  </pnp:Templates>
</pnp:Provisioning>

Make necessary changes and save this as an XML file. E.g., Pnp-Theme.xml

Step 2: PowerShell to Apply Provisioning Template

Once the template is ready, apply the template to the site using the below PnP PowerShell script.

#Config Variables
$SiteURL = "https://crescent.sharepoint.com/"
$TemplateXML  ="C:\Users\salaudeen\Desktop\Pnp-Theme.xml"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Apply provisioning Template
Invoke-PnPSiteTemplate -path $TemplateXML

Here is the script in action

set theme in sharepoint online using pnp provisioning template

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

One thought on “SharePoint Online: Apply Theme using PnP Provisioning Template PowerShell

  • When I follow these instructions, the Invoke command fails with “Template is not valid.” Any thoughts?

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *