Skip to content

Commit 0d13f9f

Browse files
authored
Merge pull request #865 from reshmee011/OOB_sitedesign
new sample script to apply OOB site design
2 parents 0897d15 + e33accd commit 0d13f9f

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Apply Out-of-the-Box SharePoint Site Designs to Existing Sites
2+
3+
## Summary
4+
5+
What if you need to apply Microsoft's out-of-the-box site designs to existing sites using automation? The PnP PowerShell, CLI for M365 and other PowerShell module cover applying custom site designs only. We can leverage a PowerShell hack using REST API calls to achieve this functionality. Thanks to Arash Aghajani who pinpointed on feasibility and requested for it to be natively available within PnP PowerShell. However the implementation with PnP PowerShell uses CSOM and does not the option to apply out of the box site design.
6+
7+
---
8+
9+
## The Challenge
10+
11+
Microsoft provides several useful out-of-the-box site designs like:
12+
- **Project Management** - Adds project-related lists and libraries
13+
- **Training Portal** - Sets up training-focused site structure
14+
- **Team Collaboration** - Configures collaboration features
15+
16+
These are available from the UI to apply to a site only. The existing PowerShell modules are lacking the functionality to replicate the behaviour.
17+
18+
---
19+
20+
## The Solution: REST API Hack
21+
22+
By using SharePoint's REST API hack through PnP PowerShell as a hack, we can programmatically apply these site designs to existing sites. Here's how to do it:
23+
24+
# [PnP PowerShell](#tab/pnpps)
25+
26+
```powershell
27+
# Configuration
28+
$siteDesignId = "b8ef3134-92a2-4c9d-bca6-2f14e79fe98e" # Project Management
29+
$webUrl = "https://yourtenant.sharepoint.com/sites/yoursite"
30+
31+
try {
32+
# Connect to SharePoint
33+
Connect-PnPOnline -Url $webUrl
34+
Write-Host "Connected to $webUrl" -ForegroundColor Green
35+
36+
# Get available site designs
37+
$getSiteDesignsUrl = "$webUrl/_api/Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.GetSiteDesigns"
38+
$siteDesigns = (Invoke-PnPSPRestMethod -Url $getSiteDesignsUrl -Method POST -ContentType "application/json" -content "{`"store`": 1}").value | select Id, Title
39+
40+
Write-Host "`nAvailable Site Designs:" -ForegroundColor Yellow
41+
$siteDesigns | ForEach-Object { Write-Host " $($_.Id) - $($_.Title)" }
42+
43+
# Validate site design ID
44+
$selectedDesign = $siteDesigns | Where-Object { $_.Id -eq $siteDesignId }
45+
if (-not $selectedDesign) {
46+
Write-Host "`nError: Site Design ID '$siteDesignId' not found!" -ForegroundColor Red
47+
Write-Host "`nAvailable Site Designs:" -ForegroundColor Yellow
48+
$siteDesigns | ForEach-Object { Write-Host " $($_.Id) - $($_.Title)" }
49+
exit 1
50+
}
51+
52+
Write-Host "`nApplying site design: $($selectedDesign.Title)" -ForegroundColor Yellow
53+
54+
# Apply the site design
55+
$restUrl = "$webUrl/_api/Microsoft.SharePoint.Utilities.WebTemplateExtensions.SiteScriptUtility.ApplySiteDesign"
56+
$body = "{`"siteDesignId`": `"$siteDesignId`", `"webUrl`": `"$webUrl`", `"store`": 1}"
57+
$response = Invoke-PnPSPRestMethod -Url $restUrl -Method Post -ContentType "application/json" -Content $body
58+
59+
Write-Host "✅ Site design '$($selectedDesign.Title)' applied successfully!" -ForegroundColor Green
60+
61+
if ($response) {
62+
Write-Host "Response details:" -ForegroundColor Cyan
63+
$response | ConvertTo-Json -Depth 3
64+
}
65+
}
66+
catch {
67+
Write-Host "❌ Error applying site design: $($_.Exception.Message)" -ForegroundColor Red
68+
}
69+
```
70+
71+
[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]
72+
73+
***
74+
75+
## Source Credit
76+
77+
Sample first appeared on [PowerShell Hack: Apply Out-of-the-Box SharePoint Site Designs to Existing Sites](https://reshmeeauckloo.com/posts/powershell-apply-outofthebox-sitedesigns/)
78+
79+
## Contributors
80+
81+
| Author(s) |
82+
|-----------|
83+
| [Reshmee Auckloo](https://github.com/reshmee011) |
84+
85+
86+
[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
87+
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-apply-OOB-sitedesign" aria-hidden="true" />
486 KB
Loading
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[
2+
{
3+
"name": "spo-apply-OOB-sitedesign",
4+
"source": "pnp",
5+
"title": "Apply Out-of-the-Box SharePoint Site Designs to Existing Sites",
6+
"shortDescription": "Apply Out-of-the-Box SharePoint Site Designs to Existing Sites",
7+
"url": "https://pnp.github.io/script-samples/spo-apply-OOB-sitedesign/README.html",
8+
"longDescription": [
9+
"Apply Out-of-the-Box SharePoint Site Designs to Existing Sites"
10+
],
11+
"creationDateTime": "2025-08-01",
12+
"updateDateTime": "2025-08-01",
13+
"products": [
14+
"SharePoint",
15+
"Sites"
16+
],
17+
"metadata": [
18+
{
19+
"key": "PNP-POWERSHELL",
20+
"value": "3.1.91"
21+
}
22+
],
23+
"categories": [
24+
"SharePoint"
25+
],
26+
"tags": [
27+
"modern",
28+
"Connect-PnPOnline",
29+
"Invoke-PnPSPRestMethod"
30+
31+
],
32+
"thumbnails": [
33+
{
34+
"type": "image",
35+
"order": 100,
36+
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-apply-OOB-sitedesign/assets/preview.png",
37+
"alt": ""
38+
}
39+
],
40+
"authors": [
41+
{
42+
"gitHubAccount": "reshmee011",
43+
"company": "",
44+
"pictureUrl": "https://avatars.githubusercontent.com/u/7693852?v=4",
45+
"name": "Reshmee Auckloo"
46+
}
47+
],
48+
"references": [
49+
{
50+
"name": "Want to learn more about PnP PowerShell and the cmdlets",
51+
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
52+
"url": "https://aka.ms/pnp/powershell"
53+
}
54+
]
55+
}
56+
]

0 commit comments

Comments
 (0)