A little late to this, but if you are using PnP CSOM
, you can do this as below:
using (ClientContext clientContext = new ClientContext(siteUrl))
{
clientContext.AuthenticationMode = ClientAuthenticationMode.Default;
clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);
ThemeManager.ApplyTheme(clientContext.Web, OfficeDevPnP.Core.Enums.SharePointTheme.Orange);
}
Also, if you are using the PnP Provisioning engine, you can use the below template XML and the use the PnP commandlet , Apply-PnPProvisioningTemplate
:
<?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-189597059C6B4C3FB113CE057D982E8E">
<pnp:ProvisioningTemplate ID="TEMPLATE-189597059C6B4C3FB113CE057D982E8E" Version="1" BaseSiteTemplate="SITEPAGEPUBLISHING#0" Scope="RootSite">
<pnp:Theme Name="Orange" IsInverted="false" />
</pnp:ProvisioningTemplate>
</pnp:Templates>
</pnp:Provisioning>
This capability was added couple of months back, so just ensure that you are using PnP CSOM and PnP PowerShell after May 2019 onwards (i.e v 3.9.x.x and above
).
The necessary OOTB theme names are available in the enum: