Before automating the creation of subsites or sites in SharePoint Online, it’s necessary to have a template available. In the modern model, templates are based on Site Designs and Site Scripts.
🏗️ Creating and Registering a SharePoint Site Template (Site Design)
📌 Introduction
Before automating the creation of subsites or sites in SharePoint Online, it’s necessary to have a template available. In the modern model, templates are based on Site Designs and Site Scripts.
This section explains how to build and register a template from scratch, using PowerShell commands against a tenant such as Contoso.
⚙️ Step 1 – Define a Site Script
A Site Script is a JSON file that describes actions SharePoint should execute when the template is applied.
Example (ContosoProjectScript.json):
{
"$schema": "schema.json",
"actions": [
{
"verb": "createSPList",
"listName": "ProjectDocuments",
"templateType": 101,
"subactions": [
{
"verb": "setDescription",
"description": "Document library for project files"
}
]
},
{
"verb": "applyTheme",
"themeName": "ContosoTheme"
}
],
"version": 1
}
This script creates a document library and applies a custom theme.
⚙️ Step 2 – Upload the Site Script
Use SharePoint Online PowerShell (or PnP PowerShell).
# Connect to tenant
Connect-SPOService -Url https://contoso-admin.sharepoint.com
# Upload the script content
$script = Add-SPOSiteScript `
-Title "Contoso Project Script" `
-Description "Creates project library and applies Contoso theme" `
-Content (Get-Content .\ContosoProjectScript.json -Raw)
This returns a GUID for the Site Script.
⚙️ Step 3 – Create a Site Design
Now link the script to a Site Design (the actual template).
Add-SPOSiteDesign `
-Title "Contoso Project Template" `
-WebTemplate "64" `
-SiteScripts $script.Id `
-Description "Template for Contoso project collaboration sites"
- Title → The friendly name (e.g., “Contoso Project Template”).
- WebTemplate “64” → Indicates it applies to a Team site.
- SiteScripts → The GUID(s) of scripts to execute.
The command returns another GUID, which is the Site Design ID (the value you will later use in automation flows).
⚙️ Step 4 – Verify the Template
List the available templates with:
Get-SPOSiteDesign
Expected output:
Id Title WebTemplate
----------------------------------- -------------------------- ------------
12345678-90ab-cdef-1234-567890abcdef Contoso Project Template 64
✅ Key Takeaways
- Site Scripts are JSON definitions of actions.
- Site Designs are published templates that reference one or more scripts.
- They are stored in the tenant’s catalog and identified by a GUID.
- These GUIDs are what you use in Power Automate or REST API calls to create subsites/sites automatically.
