SharePoint Site Scripts & Site designs

What is a site design?

A site design is a group for predefined commands or actions that gets executed after a SharePoint Site is created. Some of the actions which can be executed as a site design are setting site logo, join the site to a hub, set default theme, create lists & libraries with custom columns.

Example: When a HR related SharePoint site is setup, HR Site design can be setup to execute and add HR department color theme, logo & setup predefined lists.

What is a site script?

A site script is a JSON that defines actions that can be performed on a SharePoint site. One or more site scripts can be attached to a site design. When a site design is executed, the actions defined in all the site scripts are executed in order.

Example: Creating a list with custom columns can be defined as a site script and can be attached to multiple site designs.

If you plan on having multiple site designs, it is a good practice to define each or group of related actions into one site script. Site Designs are usually executed after site is setup. Settings up a site design does not impact existing or all sites.

Site Design that sets logo & apply a defined color theme to SharePoint sites:

Step 1: Define Custom Site Theme

Here is my sample custom theme
$customTheme = @{
"themePrimary" = "";
"themeLighterAlt" = "";
"themeLighter" = "";
"themeLight" = "";
"themeTertiary" = "";
"themeSecondary" = "";
"themeDarkAlt" = "";
"themeDark" = "";
"themeDarker" = "";
"neutralLighterAlt" = "";
"neutralLighter" = "";
"neutralLight" = "";
"neutralQuaternaryAlt" = "";
"neutralQuaternary" = "";
"neutralTertiaryAlt" = "";
"neutralTertiary" = "";
"neutralSecondary" = "";
"neutralPrimaryAlt" = "";
"neutralPrimary" = "";
"neutralDark" = "";
"black" = "";
"white" = "";
}

After your theme is defined. Add it as a custom theme to your tenant.

Add-SPOTheme -Name "Custom Theme" -Palette $customTheme -IsInverted $false -Overwrite

At the end of first step, you have a custom theme defined and added. If you don’t want users to select other available themes, you can hide all available options by running below PowerShell cmdlet.

Set-SPOHideDefaultThemes $true

At this point, only your custom theme is available to select.

Step 2: Create site script

This site script will include 2 actions. Applying custom theme & setting site logo. Custom theme is defined in step 1.

$siteScript = @'
{
"$schema": "schema.json",
"actions": [
{
"verb": "applyTheme",
themeName: "Custom Theme" //this is the custom theme defined in step 1.
},
{
"verb": "setSiteLogo",
"url": "logo url"

}
],
"bindata": {},
"version": 1
}
'@
#Add site script to Tenant
Add-SPOSiteScript -Title "Custom default" -Content $siteScript -Description "Sample default design"

Below information is displayed after site script is added to the tenant.

Id : GUID
Title : Custom default
Description : Sample default design
Content :
Version : 1

Note down the GUID. We need it in next step.

Step 3: Add Site design

Like we discussed earlier, one or more site scripts can be attached to a site design. Site scripts are identified by their GUID’s.

Add-SPOSiteDesign -Title "Team Site Design" -WebTemplate "64" -SiteScripts "GUID" -Description "Cusotm default design"

Site designs are attached to web templates. In the above example we attached our custom site design to Team site web template.

WebTemplate ID

  • #64 – Team Site
  • #68 – Communication Site
  • #1 = Groupless Team site

Step 4: Setting Site design as default

To execute site design whenever a new site is created, we need to set site design as default.

Set-SPOSiteDesign -Identity $siteDesignId -IsDefault:$isDefault

Once the above 4 steps are setup. Whenever a Team site is created our custom site design executes and sets the custom theme & site logo. You can confirm the execution of site design by selecting the gear icon in top right corner of new site and selecting site designs.Applied Site Designs

It will display the site design which are applied to the site. It will also display available site designs which can be manually applied to the site.Available Site Designs