Pergunta

In our new Modern Sites we can change the themes easily from a list of default ones. As shown below.

enter image description here

Now as per my assumptions the names of these default themes are Red, Blue, Orange etc.

I am provisioning new Modern Sites using PnP code. I have seen many articles mentioning easy to create a custom theme and set them. (PS cmd: Set-PnPWebTheme OR c#: Tenant.SetWebTheme)

But how can we set one of the default ones? Like while provisioning a modern site I want to set "Red" as a default theme for my site collection.

Foi útil?

Solução

There is no way to set the default themes using Powershell.

What you can do, is copy the default theme, add it as a custom one and apply the copied/custom theme.

Outras dicas

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:

enter image description here

Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top