How To Create Custom Site Template In SharePoint Online? [Modern SharePoint]

Recently, we received a requirement from the client that he needs to create a SharePoint site as a template at the organizational level so that users can create a SharePoint site from that custom template and also apply this custom template to an existing SharePoint site.

In this tutorial, I will explain how we can create a SharePoint site as a template at the tenant level.

Create SharePoint site templates at the Organization Level [Using SPO cmds]

Let me show you how to create an existing SharePoint site as a template using SharePoint Online Management Shell commands. These commands are used to manage the SharePoint site settings at the organization and site collection levels.

Note: To use these commands, you must have a SharePoint Admin role in Microsoft 365. Also, you just install the SharePoint Online Management Shell Module and connect to the SharePoint Online services.

Here is the SharePoint site I want to use as a template for SharePoint Online. The Site type is Team site.

create a team site template in SharePoint Online using pnp powershell

Let’s start by following the steps below to create a SharePoint site as a template.

1. Connect with your SharePoint tenant using the SPO command. Open the SharePoint Online Management Shell and run the command below, it will ask you to log in with your admin credentials.

Connect-SPOService -Url "https://tenantname-admin.sharepoint.com/"
how to create sharepoint site template from existing site

2. Define the SharePoint lists that you want to include in the SharePoint template, as shown below.

$IncludedLists = @("Lists/ProjectsList", "Lists/ProjectTasks","Lists/ProjectBudget", "Lists/ProjectGanttChart","Lists/Tasks","Site Pages")
how to add an existing site to sharepoint online as a site template

3. Add the below code to get the schema from the SharePoint site:

$SiteSchema = Get-SPOSiteScriptFromWeb -WebURL "https://tenantname.sharepoint.com/sites/ProjectManagement" -IncludeBranding  -IncludeTheme -IncludeRegionalSettings -IncludeSiteExternalSharingCapability -IncludedLists $IncludedLists

Here, the Get-SPOSiteScriptFromWeb cmd extracts the site schema, which includes theme, branding, regional settings, external sharing capabilities, and lists that we stored in the $IncludedLists variable, and stores it in the $SiteSchema variable.

For this WebURL, provide your SharePoint site address, which you want to make it as a custom template.

save SharePoint online site as template url

4. Run the command below to add the extracted site script to the tenant.

$SiteScript = Add-SPOSiteScript -Title "Project Management Site Template v1" -Content $SiteSchema

Here the Add-SPOSiteScript command will create a new site script in SharePoint Online.

  • Title = Specifies the name of the site script being created.
  • Content = Provides the content of the site script’s structure and actions. This defines what customizations, configurations, the script will apply to a site.
save site as template sharepoint online using SPO commands

5. Run the below command to create a site design:

$SiteDesign = Add-SPOSiteDesign -Title "Project Management Site Template v1" -WebTemplate 64 -SiteScripts $SiteScript.Id

The Add-SPOSiteDesign creates a new site design in SharePoint Online.

  • Title “Project Management Site Template v1” = specifies the name of the site design being created.
  • WebTemplate 64= It defines the SharePoint site template type. 64 for the Team site and 68 for the communication site template.
  • -SiteScripts $SiteScript.Id: It links the site script to the site design by specifying the script’s ID variable. The site script defines the actions and customizations to be applied to the site.
save sharepoint site as template

6. To check whether the Site design and script have been added to SharePoint Online, run the below commands one by one. It will give the site script id and some other details also for the site design:

 Get-SPOSiteScript
Get-SPOSiteDesign
upload sharepoint online site as template to sharepoint tenant

7. Open the SharePoint Online admin center; the URL is below. Under Sites ->Click on Active Sites -> Choose Team Site -> Choose From Organization. You’ll see the custom site there, so you can create a new SharePoint team site by choosing this.

how to create a site template in sharepoint online

This way we can make a SharePoint site as a template and make it available in the tenant so that everyone can create a new SharePoint site from this template.

8. Use the below command if you want to delete the custom template that you created.

Remove-SPOSiteDesign -Identity "provide site design id"

Here, the Remove-SPOSiteDesign command will delete the SharePoint site template in SharePoint Online. For the identity property, provide the existing template site design id. To get site template design ID use this command Get-SPOSiteDesign.

Create SharePoint site templates at the Organization Level [Using PnP cmds]

Here, we’ll see how to create a site template in SharePoint Online using PnP PowerShell commands. In the example below, you can see I added the SharePoint site template v2 to SharePoint Online.

How to save a site as a template in SharePoint Online using pnp powershell

Follow the steps below to achieve this!

1. First, connect to the SharePoint site using the Connect-PnPOnline command. Then, run the below PnP PowerShell command in VSCode or on any other platform like Windows PowerShell ISE.

Connect-PnPOnline -Url "https://tenantname.sharepoint.com/sites/ProjectManagement" -Interactive -ClientId 736547-2364-34734-5455

2. Provide the SharePoint list names into an array that you want to include in the site template.

$IncludedLists = @("Lists/ProjectsList", "Lists/ProjectTasks","Lists/ProjectBudget", "Lists/ProjectGanttChart","Lists/Tasks","Site Pages")

3. Add the below command to add the SharePoint site schema into a variable.

$SiteSchema = Get-PnPSiteScriptFromWeb -Lists $IncludedLists -IncludeAll

The Get-PnPSiteScriptFromWeb command will get the site schema.

  • Lists = Provide the array name $IncludedLists to this parameter.
  • IncludeAll = To include all components add this parameter.

4. Add the extracted site schema to SharePoint Online by running the below command.

$SiteScript = Add-PnPSiteScript -Title "Project Management Site Template v2" -Content $SiteSchema

The Add-PnPSiteScript command will add the site script to SharePoint Online.

  • Title = Site schema template name “Project Management Site Template v2.”
  • Content = Add the JSON extracted site script to this parameter.

5. Run the below command to get the added site script ID.

Get-PnPSiteScript -Identity $SiteScript.Id

The Get-PnPSiteScript command will get the ID of the previously added site script.

6. Run the below command to add the site design into SharePoint Online.

$SiteDesign = Add-PnPSiteDesign -Title "Project Management Site Template v2" -WebTemplate 64 -SiteScriptIds "48924813-4c28-4330-b40d-146e4c7d18f3"

The Add-PnPSiteDesign command will add the site design to SharePoint Online.

  • Title =Provide site design template name.
  • WebTemplate = Provide webtemplate number, for SharePoint Online Team site 64, for communication site 68.
  • SiteScriptIds = Add the previously got site script ID to this parameter.
create a site template out of the current team site in SharePoint Online using pnp powershell

7. Run the command below to get the newly added site design ID.

Get-PnPSiteDesign -Identity $SiteDesign.Id

The Get-PnPSiteDesign command will fetch the added site designs, to fetch a specific one, add the Identity parameter for the one you want to provide, $SiteDesign.Id

8. To delete the added site template using this PnP PowerShell commands, run the below command.

Remove-PnPSiteDesign -Identity $SiteDesignId

$SiteDesignId is a variable that contains the Site design ID.

Now check the SharePoint admin center, there, you’ll find the newly added SharePoint site template using PnP PowerShell.

I hope you understand how to add an existing SharePoint site template in SharePoint Online. In this article, I have explained two different ways: using SharePoint Online ManagementShell and PnP PowerShell commands. I also explained how to delete the added site template in SharePoint Online.

Follow this article if you want to add an existing SharePoint template at the SharePoint Online tenant level so that everyone can create a SharePoint site with this custom template.

Also, you may like:

Power Apps functions free pdf

30 Power Apps Functions

This free guide walks you through the 30 most-used Power Apps functions with real business examples, exact syntax, and results you can see.

Download User registration canvas app

DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App