|
| 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" /> |
0 commit comments