SharePoint Site Designs and Scripts – Part 1

SharePoint Site Designs and Scripts are finally here! In this blog series I’ll take a closer look at the available actions and configuration options which can be applied using Site Designs and Scripts.

Once deployed, the Site Design appears alongside the default SharePoint templates:

Capture1

So, how to create and deploy my own design?

Firstly, a list of actions needs to be created in JSON format – Site Script. The list of available actions can be found here: https://docs.microsoft.com/en-us/sharepoint/dev/declarative-customization/site-design-json-schema . The script can be saved as a file or stored it in a variable as in my example below:

$site_script = @'
{
 "$schema": "schema.json",
     "actions": [
         
		 {
			"verb": "addNavLink",
			"url": "https://www.risual.com",
			"displayName": "risual website",
			"isWebRelative": false
		},
		{
			"verb": "addNavLink",
			"url": "https://www.gnu-tech.com",
			"displayName": "My Blog",
			"isWebRelative": false
		},
		{
			"verb": "setRegionalSettings",
			"timeZone": 2, /* Greenwich Mean Time */
			"locale": 2057, /* UK */
			"sortOrder": 25, /* General */
			"hourFormat": "24"
		}		 
             ]
         }
     ],
         "bindata": { },
 "version": 1
}
'@

There are 3 actions in the script – add 2 links to the navigation and set site’s regional setting.

At the time this blog is written Microsoft supports max 30 script actions. This includes sub-actions so creating a site content type and adding 5 site columns to that content type is counted as 6 actions.

Next, the Site Script needs to be added using Add-SPOSiteScript cmdlet.

Add-SPOSiteScript -Title "Base Configuration Script" -Content $site_script 
-Description "Adds links to global navigation and sets site regional settings"

Finally, using the ID from the results of the previous cmdlet, the Site Design needs to be added to the tenant:

Add-SPOSiteDesign -Title "Base Configuration Template" -WebTemplate "68" 
-SiteScripts "39381767-2cbf-44c2-b520-b1924e41da6a" -Description "Adds links 
to global navigation and sets site regional settings"

In my example I used “68” with the -WebTemplate switch, this associates my Site Design with  the Communication Site; “64” indicated modern Team site template.

That’s it. The site design is ready to use. The script runs straight after a site is created and a summary of actions is displayed after it finishes:

Capture2

The script can be updated after it’s deployed by using Set-SPOSiteScript; this change will not affect existing sites.

In my next post, I’ll look into how Site Designs can be scoped to specific groups of users and how to update the default SharePoint Site Designs (Topic, Showcase and Blank).

About the author