SharePoint Online: Create Site Design and Site Scripts using PowerShell

What are Site Design and Site Scripts in SharePoint Online?

Site design and site scripts are the new way to create site templates in SharePoint Online. Say, you want to create sites with a specific theme, apply a logo, set regional settings, create a list or library in the site, add users, create a content type and columns, add-remove links from the navigation, trigger a flow, Join to hub-site, add-remove site columns, etc. – then make use of site designs. The best part is not only for new sites, but you can also apply site designs to any existing sites to deploy the artifacts and make them consistent. Remember, Feature stapling? Here too, you create a site design and register it with SharePoint Online site templates such as a team site, or communication site.

A site script is a JSON file with a set of predefined action definitions to be executed when you apply site design. A site design acts as a container for the site script(s). You can attach one or more site scripts to the site design (and a site script can be attached to more than one site design!), and when you apply the site design, you execute the actions defined in all the site scripts, and they will run in the order listed. Please note, site design is not really a site template that gets attached to the sites – but a set of actions executed when you apply a site design. So, changing site designs doesn’t change anything on existing sites (until you re-apply the site design).

How to Create a Site Design in SharePoint Online?

Basically, the creation of site design works like this: You create a site script using a JSON template with desired actions to run, such as creating lists, applying a theme, etc., and then adding the script to your tenant. The next step is to create a site design and add the site script to the design. While creating site design, you have to associate it with any modern site templates, such as a team site or communication site template. That’s all. Once it’s ready, you can apply it either to new or existing sites. Here is my sample site design and script:

#Define Sitescript JSON
$JSONScript = @"
{
  "$schema": "schema.json",
  "actions": [
    {
      "verb": "applyTheme",
      "themeName": "Corporate Theme"
    },
    {
      "verb": "setRegionalSettings",
      "timeZone": 24,
      "sortOrder": 25,
      "hourFormat": "12"
    },
    {
      "verb": "setSiteLogo",
      "url": "/Style Library/logo.jpg"
    },
    {
      "verb": "createSPList",
      "listName": "Work",
      "templateType": 101,
      "subactions": [
        {
          "verb": "setTitle",
          "title": "Work"
        }
      ]
    }
  ],
  "bindata": {},
  "version": 1
}
"@
 
#Set Parameters
$AdminCenterURL = "https://crescent-admin.sharepoint.com/"
 
#Connect to SharePoint Online
Connect-SPOService -Url $AdminCenterURL -Credential (Get-Credential)
 
#Add Site Script
$SiteScript = $JSONScript | Add-SPOSiteScript -Title "Crescent Site Script"
 
#Add Site Design
$WebTemplate = "64" #64 = Team Site, 68 = Communication Site, 1 = Team Site without Group
Add-SPOSiteDesign -Title "Crescent Site Template" -WebTemplate $WebTemplate -SiteScripts $SiteScript.ID -Description "Crescent Site Template"

Deploy a site design in SharePoint Online

  1. Create a site script JSON Schema of required actions as per Microsoft Site design schema reference. You can also use this online tool to generate JSON schema Online JSON Designer: https://www.sitedesigner.io/, You can use my above JSON to set a theme, apply a logo, configure regional settings, and create a document library.
  2. Use the above PowerShell script to create a site script and site design. You can create up to 100 site scripts and 100 site designs per tenant!
  3. Now, you can use this site design either for new sites or apply it to new or existing ones. Here is how it works on new sites:
    • Go to SharePoint Online site >> Click on Settings >> Click on “Apply a Site Template”.
    • You’ll see the custom site design listed in the drop-down. In my case, it is the “Crescent Site Template”. 
      create a site template sharepoint online
    • Click on the “Use template” button to trigger site creation. Once the site is created, you’ll see the actions defined in the site script is being applied.
      sharepoint online site templates

When the actions in the scripts are completed, SharePoint displays detailed results of those actions in a progress pane. Some more PowerShell cmdlets to manage site scripts and site designs in SharePoint Online:

  • Get-SPOSiteDesign – Retrieves all site designs created in the tenant
  • Get-SPOSiteScript – Gets the list of site scripts available
  • Set-SPOSiteDesign – Update existing site design
  • Set-SPOSiteScript – Update the site script JSON
  • Remove-SPOSiteScript – Deletes the given site script
  • Remove-SPOSiteDesign  -Removes the given site design ID
  • Invoke-SPOSiteDesign – Apply site design on the existing site
  • Grant-SPOSiteDesignRights – Set permissions to use site designs
  • Revoke-SPOSiteDesignRights – Remove site design permissions

and here are some examples:

Get existing site script and Site Designs:

Get-SPOSiteScript
Get-SPOSiteDesign

Update existing site script:

$SiteScriptId = "e694f7f2-ed9b-48ca-abe4-fb4fedc33c31"
$SiteScriptFile = "c:\Temp\sitescript.json"
Set-SPOSiteScript -Identity $SiteScriptId -Content (Get-Content $SiteScriptFile -Raw)

Update existing site Design:

$SiteDesignId = "4d086b5b-c7a5-4b60-a3c5-e572ff0a6b8d"
Set-SPOSiteDesign -Identity $SiteDesignId -SiteScripts "d4708c15-949c-491f-8503-cd2a67a1de66", "36f5796f-dee2-4983-80af-a08d2951df86"

Apply site Design on Existing Site:

#Set Parameters
$AdminCenterURL = "https://crescent-admin.sharepoint.com/"
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$SiteDesignId = "4d086b5b-c7a5-4b60-a3c5-e572ff0a6b8d"

#Connect to SharePoint Online
Connect-SPOService -Url $AdminCenterURL -Credential (Get-Credential)

#Apply Site Design
Invoke-SPOSiteDesign -Identity $SiteDesignId -WebUrl $SiteURL

Set Site Design as Default:

Set-SPOSiteDesign -Identity $SiteDesignId -IsDefault:$True

Delete existing site script and site design:

Remove-SPOSiteDesign -Identity "f6611c71-dba5-4a32-8811-51472b7e5961"
Remove-SPOSiteScript -Identity "b2ac88ee-2711-4cbc-bea9-bf63e22af735"

Conclusion

In conclusion, creating site designs and site scripts in SharePoint Online is a powerful way to automate the creation of customized sites and ensure consistency across your organization’s SharePoint environment. Site designs allow you to define a set of actions that will be performed when a new site is created, such as adding lists, pages, and web parts. Site scripts allow you to define the structure and content of a new site, such as creating lists, libraries, and pages. By following these steps, you can easily create custom site designs and site scripts that can be used to create new sites in SharePoint Online with the desired structure and content.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

6 thoughts on “SharePoint Online: Create Site Design and Site Scripts using PowerShell

  • I am creating a Content type “CT1” using “verb”: “createContentType”. Then adding 5 columns to CT1 in sub actions. Now, How can I add a “Shapes” lookup to “CT1” ?
    If I use following snippet inside sub actions then it gives error in CreateContentType. If I use it outside of subactions of CreateContentType then it gives errors in Lookup snippet.
    Please help.

    {
    “verb”: “addSPLookupFieldXml”,
    “schemaXml”: “”,
    “targetListName”: “Shapes”
    }

    Reply
  • I’m getting error while attempting to Add-SPOSiteDesign, then it is giving below error.
    Add-SPOSiteScript : Action 7 (createSPList) is invalid. Template type specified is not supported.

    Reply
    • Use:

       {
            "verb": "setRegionalSettings",
            "timeZone": 4,
            "locale": 1033,
            "sortOrder": 6,
            "hourFormat": "24"
          }
      
      Reply
  • Hi,
    Thanks for sharing this however it is no longer relavent as Microsoft has made changes to how you know apply templates to sites.

    We have been using site design to trigger flows and azure functions to apply pnpSiteTemplates but this cannot be done when the site is created anymore only after the site has been provisioned can you manually choose a custom template.

    Reply
  • Another excellent article. I’ve created a site template/design it works great, but i’d like to disinherit permissions for the libraries i’m creating. My example Json Script is:
    {
    “verb”: “createSPList”,
    “listName”: “DataRoom1”,
    “templateType”: 101,
    “subactions”: [
    {
    “verb”: “setDescription”,
    “description”: “This is a modified default Directory for External Access”
    }
    ]

    Many thanks

    Ronan

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *