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?

Go to PnP Provisioning Schema repository in GitHub and build your provisioning template. https://github.com/SharePoint/PnP-Provisioning-Schema, Here is mine:

Provisioning Template Schema XML for Theme:

<?xml version="1.0"?>
<pnp:Provisioning xmlns:pnp="http://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 a XML file. E.g. Pnp-Theme.xml

PowerShell to Apply Provisioning Template

Once the template is ready, apply the template to the site using 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 -UseWebLogin

#Apply provisioning Template
Apply-PnPProvisioningTemplate -path $TemplateXML

Here is the script in action

set theme in sharepoint online using pnp provisioning template

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply