Site scripts and Site Templates are a way to apply custom configurations on top of existing sites to keep them uniform across the tenant with respect to List Templates, Themes, Branding, External Sharing Settings, etc:
Site scripts are JSON files that specify an ordered list of actions to run when creating the new site. The actions are run in the order listed. The following example is a script that has one action verb: createSPList which would create a list by the name Covid Protection and create the defined site columns, content type as part of it.
Each action in a site script is specified by a verb value in the JSON. In the previous script, the action is specified by the createSPList verb which creates the list. We can use various other available verbs to achieve the functionalities like :
- Creating a new list or library (or modifying the default one created with the site)
- Creating site columns, content types, and configuring other list settings
- Set site branding properties like navigation layout, header layout and header background
- Applying a theme
- Setting a site logo
- Adding links to quick launch or hub navigation
- Triggering a Power Automate flow
- Installing a deployed solution from the app catalog
- Setting regional settings for the site
- Adding principals (users and groups) to SharePoint roles
- Setting external sharing capability for the site
Site templates were previously called Site Designs. It acts as a wrapper and container for the actions defined in the Site Script. Site templates can be used each time a new site is created to apply a consistent set of actions defined in the site script. Application of Site design to an existing site can be done out of the box as well as programmatically. Out of the box, the option is available in Site Settings
Selecting Apply a Site Template will give us OOB Site Templates as well as the Custom Site Templates we have created.
In this article, we will see how to extract the Customized Site actions as a Site Script and create a Site Template out of it so that it can be reused across sites. We can extract Themes, branding, regional settings, External Sharing settings, List and columns as part of the Site Script and create a Site design.
We can extract the Site Script from an existing site using the Get- SPOSiteScriptFromWeb cmdlet which has the syntax:
We will extract the Theme 1 Library and 1 List from the source site using the below command
|$extractedContent = Get-SPOSiteScriptFromWeb `|
-WebUrl https://office365journey.sharepoint.com/sites/2021CovidActions/ `
-IncludedLists (“Covid Prevention”, “Lists/Covid Medicine Inventory”)
We will then add the Site Script to SharePoint Online using the Add-SPOSiteScript command by passing in the extracted JSON verb as a parameter along with the title and description
-Title “Covid Actions” `
-Description “This is a copy of Covid Action Site” `
Copy the ID of the Site Script as we will be using in the next step
Finally let’s apply the site Design by using the command Add-SPOSiteDesign and pass the Title, Web Template, and Site Script as the parameters.
Once we head over to Site Settings ->Apply Site Template, we can see the recently added Site Template which houses the extracted site script actions.
Selecting Covid Action Site Template will show the actions that will be applied which shows the application of theme and provisioning of the list and library.
Clicking on the use template will apply it on top of the existing site. We can see that the existing Blue theme has been applied and the list and library are now present on the new Site.
Thus we saw how to extract a Site Script out of an existing site and create a Site Design/template out of it, add it to the SharePoint Online collection and later apply it on top of an existing site.