Skip to content

Commit af84e53

Browse files
authored
Merge pull request #877 from a1mery/spo-apply-site-theme
New script sample to apply a theme to a SharePoint site
2 parents b0deaa5 + f4684fc commit af84e53

File tree

4 files changed

+138
-0
lines changed

4 files changed

+138
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
3+
# Apply site theme
4+
5+
## Summary
6+
7+
Apply a theme to a specific SharePoint site without adding a tenant theme that would be available for all sites through the "Change the look" menu.
8+
9+
![Example Screenshot](assets/preview.png)
10+
11+
12+
# [PnP PowerShell](#tab/pnpps)
13+
14+
```powershell
15+
16+
$siteUrl = "https://contoso.sharepoint.com/sites/DemoSite"
17+
18+
$themePalette = @{
19+
"palette" = @{
20+
"themePrimary"= "#1BF242";
21+
"themeLighterAlt"= "#0d0b00";
22+
"themeLighter"= "#0b35bc";
23+
"themeLight"= "#322d00";
24+
"themeTertiary"= "#6a5f00";
25+
"themeSecondary"= "#1B22F2";
26+
"themeDarkAlt"= "#ffe817";
27+
"themeDark"= "#ffed4b";
28+
"themeDarker"= "#fff171";
29+
"neutralLighterAlt"= "#252525";
30+
"neutralLighter"= "#282828";
31+
"neutralLight"= "#313131";
32+
"neutralQuaternaryAlt"= "#3f3f3f";
33+
"neutralQuaternary"= "#484848";
34+
"neutralTertiaryAlt"= "#4f4f4f";
35+
"neutralTertiary"= "#c8c8c8";
36+
"neutralSecondaryAlt"= "#d0d0d0";
37+
"neutralSecondary"= "#dadada";
38+
"neutralPrimary"= "#ffffff";
39+
"neutralDark"= "#eaeaea";
40+
"black"= "#f8f8f8";
41+
"white"= "#1f1f1f";
42+
"primaryBackground"= "#1f1f1f";
43+
"primaryText"= "#ffffff";
44+
"error"= "#ff5f5f"
45+
}
46+
}
47+
48+
Connect-PnPOnline -Url $siteUrl -ClientId "" -Interactive
49+
50+
$accessToken = Get-PnPAccessToken -ResourceTypeName SharePoint
51+
$bodyObject = @{
52+
name = "Sample theme"
53+
themeJson = ($themePalette | ConvertTo-Json -Depth 10 -Compress)
54+
}
55+
56+
$bodyJson = $bodyObject | ConvertTo-Json -Depth 10
57+
58+
$headers = @{
59+
"Authorization" = "Bearer $accessToken"
60+
"Accept" = "application/json;odata.metadata=minimal"
61+
"Content-type" = "application/json; charset=utf-8"
62+
"ODATA-VERSION" = "4.0"
63+
}
64+
65+
$uri = "$siteUrl/_api/thememanager/Applytheme"
66+
67+
Invoke-RestMethod -Method POST -Uri $uri -Headers $headers -Body $bodyJson
68+
69+
Disconnect-PnPOnline
70+
71+
```
72+
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
73+
74+
75+
***
76+
77+
## Contributors
78+
79+
| Author(s) |
80+
|-----------|
81+
| [Aimery Thomas](https://github.com/a1mery)|
82+
83+
[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
84+
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-apply-site-theme" aria-hidden="true" />
328 KB
Loading
58.7 KB
Loading
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[
2+
{
3+
"name": "spo-apply-site-theme",
4+
"source": "pnp",
5+
"title": "Apply site theme",
6+
"shortDescription": "Apply a theme to a specific SharePoint site without adding a tenant theme that would be available for all sites.",
7+
"url": "https://pnp.github.io/script-samples/spo-apply-site-theme/README.html",
8+
"longDescription": [
9+
"Apply a theme to a specific SharePoint site without adding a tenant theme that would be available for all sites through the 'Change the look' menu."
10+
],
11+
"creationDateTime": "2025-10-22",
12+
"updateDateTime": "2025-10-22",
13+
"products": [
14+
"SharePoint"
15+
],
16+
"metadata": [
17+
{
18+
"key": "PNP-POWERSHELL",
19+
"value": "3.1.0"
20+
}
21+
],
22+
"categories": [
23+
"Configure"
24+
],
25+
"tags": [
26+
"Connect-PnPOnline",
27+
"Get-PnPAccessToken",
28+
"Invoke-RestMethod",
29+
"Disconnect-PnPOnline"
30+
],
31+
"thumbnails": [
32+
{
33+
"type": "image",
34+
"order": 100,
35+
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-apply-site-theme/assets/preview.png",
36+
"alt": "Preview of Apply site theme script"
37+
}
38+
],
39+
"authors": [
40+
{
41+
"gitHubAccount": "a1mery",
42+
"pictureUrl": "https://github.com/a1mery.png",
43+
"name": "Aimery Thomas"
44+
}
45+
],
46+
"references": [
47+
{
48+
"name": "Want to learn more about PnP PowerShell and the cmdlets",
49+
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
50+
"url": "https://aka.ms/pnp/powershell"
51+
}
52+
]
53+
}
54+
]

0 commit comments

Comments
 (0)