Create SharePoint Modern Team Site Using Site Scripts And Site Designs

We know that some of the widely used features of SharePoint on-premises do not exist in SharePoint Online. Site templates are one of them. But we usually wonder what the solution is. The solution is “Site designs”. In this article, we are going to see how to create Site Designs and how can we use it to create team sites. We will be performing all the operations related to Site designing using PowerShell and SharePoint Online Management Shell.

Steps involved in creating a team site using SharePoint site designs with custom themes.

  • Generate Theme
  • Add Theme to the site
  • Create Site Script
  • Add Site design
  • Create Team site

Generate Theme

Microsoft has provided an excellent Theme generator, through which we can easily generate a color theme for the site design. The generator gets the primary color, body text color, body background color and generates the complete theme using the combination of related colors. The output of the generator will be in three types: JSON, SASS and PowerShell. I am going to pick the PowerShell content. I have selected a dark red theme.

Create SharePoint Modern Team Site Using Site Scripts And Site Designs

The output will be something like the below, 
  1. @ {  
  2.     "themePrimary" = "#be0000";  
  3.     "themeLighterAlt" = "#080000";  
  4.     "themeLighter" = "#1f0000";  
  5.     "themeLight" = "#390000";  
  6.     "themeTertiary" = "#730000";  
  7.     "themeSecondary" = "#a80000";  
  8.     "themeDarkAlt" = "#c61414";  
  9.     "themeDark" = "#cf3232";  
  10.     "themeDarker" = "#db6060";  
  11.     "neutralLighterAlt" = "#0b0b0b";  
  12.     "neutralLighter" = "#151515";  
  13.     "neutralLight" = "#252525";  
  14.     "neutralQuaternaryAlt" = "#2f2f2f";  
  15.     "neutralQuaternary" = "#373737";  
  16.     "neutralTertiaryAlt" = "#595959";  
  17.     "neutralTertiary" = "#f6f2f2";  
  18.     "neutralSecondary" = "#f8f4f4";  
  19.     "neutralPrimaryAlt" = "#f9f6f6";  
  20.     "neutralPrimary" = "#f2eaea";  
  21.     "neutralDark" = "#fcfafa";  
  22.     "black" = "#fdfdfd";  
  23.     "white" = "#000000";  
  24.     "bodyBackground" = "#000000";  
  25.     "bodyText" = "#f2eaea";  
  26. }  
Add Theme to the site

To add the above theme to the site, we can run the below PowerShell script. Make sure that you’re a tenant admin, before running the script.

Create a variable $themepallette and assign the object value which you received from the previous step.

  1. $themepallette = @ {  
  2.     "themePrimary" = "#be0000";  
  3.     "themeLighterAlt" = "#080000";  
  4.     "themeLighter" = "#1f0000";  
  5.     "themeLight" = "#390000";  
  6.     "themeTertiary" = "#730000";  
  7.     "themeSecondary" = "#a80000";  
  8.     "themeDarkAlt" = "#c61414";  
  9.     "themeDark" = "#cf3232";  
  10.     "themeDarker" = "#db6060";  
  11.     "neutralLighterAlt" = "#0b0b0b";  
  12.     "neutralLighter" = "#151515";  
  13.     "neutralLight" = "#252525";  
  14.     "neutralQuaternaryAlt" = "#2f2f2f";  
  15.     "neutralQuaternary" = "#373737";  
  16.     "neutralTertiaryAlt" = "#595959";  
  17.     "neutralTertiary" = "#f6f2f2";  
  18.     "neutralSecondary" = "#f8f4f4";  
  19.     "neutralPrimaryAlt" = "#f9f6f6";  
  20.     "neutralPrimary" = "#f2eaea";  
  21.     "neutralDark" = "#fcfafa";  
  22.     "black" = "#fdfdfd";  
  23.     "white" = "#000000";  
  24.     "bodyBackground" = "#000000";  
  25.     "bodyText" = "#f2eaea";  
  26. }  
  27. Connect - SPOService - Url https: //<your_tenant>-admin.sharepoint.com  
  28.     Add - SPOTheme - Name "Dark Red" - Palette $themepallette - IsInverted $false  

I have named my theme dark red. After adding this theme to the site, we can select it through the change option of a modern team site.

Create SharePoint Modern Team Site Using Site Scripts And Site Designs

 

After choosing the new theme, you can immediately see the change of the look and feel. Select apply to utilize the new theme.

Create SharePoint Modern Team Site Using Site Scripts And Site Designs

 

But our intention is not to change it manually; instead, utilize the existing theme and apply it to our new modern team site.

Create Site Script

Site script is also a modern JSON file which helps in creating the site design. It will be in the below format.

  1. {  
  2.     "$schema""schema.json",  
  3.     "actions": [... < one or more verb actions > ...],  
  4.     "bindata": {},  
  5.     "version": 1 < to define the script version >  
  6. };  

Some of the basic things which we can perform through site scripts are

  • Applying the theme to the site
  • Creating a list
  • Add/Delete SP Field
  • Add SP Field using XML
  • Add SP Lookup field using XML
  • Add/Remove SP View
  • Add/Remove Content type
  • Set SP Field Custom Formatter
  • Associate Field Customizer Extensions
  • Associate List View Command set Extensions
  • Add/Remove Navigations
  • Set site logo
  • Join a hub site
  • Install an add-in or solution
  • Register an Extension
  • Configure Regional settings
  • Trigger a Microsoft Flow
  • Add users to SP Group
  • Manage guest access

The above things are mentioned in the Microsoft JSON Schema documentation. Below is the sample site script JSON which applies the theme. I will be writing a few more blogs to explain how to perform the remaining operations using site scripts.

  1. {  
  2.     "$schema""schema.json",  
  3.     "actions": [{  
  4.         "verb""applyTheme",  
  5.         "themeName""Dark Red"  
  6.     }],  
  7.     "bindata": {},  
  8.     "version": 1  
  9. };  

To add a site script to Office 365 tenant, we need to execute the below PowerShell script after connecting to the tenant admin site using SPOService.

  1. Get-Content '<folder_location_to_site_script>\SiteScript.json'-Raw | Add-SPOSiteScript -Title "Dark Red Theme Site Script"  

The above command would return site script ID (GUID), and store it somewhere in the site design script.

Create SharePoint Modern Team Site Using Site Scripts And Site Designs

Add Site design

The site design will be acting as the site template, which will define the structure for a customized team site. To add the site design to the Office365 we need to execute the below PowerShell script. Here we can mention multiple site scripts, which should be executed one by one. Right now, we have only one site script. I am including the site script ID after running it in the PowerShell ISE.

  1. Add-SPOSiteDesign -Title "Custa om site design" -WebTemplate "64" -SiteScripts " 0a42a67d-137a-4a07-8f37-e184c2703069" -Description "Creates a custom team site with the default dark red theme”  

After execution, we will get a response similar to below.

Create SharePoint Modern Team Site Using Site Scripts And Site Designs

Create Team site

As soon as we run the above script, the site design will be available as a template in the team site.

Create SharePoint Modern Team Site Using Site Scripts And Site Designs

Create SharePoint Modern Team Site Using Site Scripts And Site Designs

While creating the team site, choose the custom site design template to see the magic. It will show the script which is executing on the screen.

Create SharePoint Modern Team Site Using Site Scripts And Site Designs

 

The updated site will look like below.

Create SharePoint Modern Team Site Using Site Scripts And Site Designs

 

I hope you learned how to apply a theme using site designs. This helps the organization to maintain the same color theme when creating each and every team site. Feel free to fill in the comment box below.

Happy SharePointing!!!