Create subsites in SharePoint Online using Workflow with a custom template – Part I

PART I : RETREIVE THE CUSTOM TEMPLATE ID
In order to create a subsite with a custom template you must retrieve the “template id” of the template. The easiet eay to achieve this is to use a PowerShell script. Follow the steps below to retrieve the “template id”.

1.     Ensure your computer has the following installed

a.  SharePoint Online Management Shell

b.  SharePoint Online Client Components SDK

2.     Copy and paste the following code into a text file with a file extension of ps1 and save it locally on your computer (e.g. c:\scripts\listtemplateid.ps1)

Add-Type -Path “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll”

Add-Type -Path “C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll”

$Username = “<<SiteCollectionAdminUser>>”

$Password = Read-Host -Prompt “Please enter your password” -AsSecureString

$Site = “<<SiteCollectionURL>>”

$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site)

 

$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username,$Password)

$Context.Credentials = $Creds

 

#List Custom Templates

$Templates = $Context.Site.GetWebTemplates(“1033″,”0”)

$Context.Load($Templates)

$Context.ExecuteQuery()

$Templates | Where {$_.Name -like “*{*” } | Select Name, Description

 

3.     Replace <<SiteCollectionAdminUser>> with a site collection administrator username where the template resides within

4.     Replace the <<SiteCollectionURL>> with the site collection URL where the template resides within

5.     Open up a SharePoint Online Management Shell and type the following commands

a.      cd c:\scripts

b.     .\ listtemplateid.ps1

6.     When prompted type in the password for the username that is referenced in the PowerShell script

7.       The script will then list the templates under the specified Site Collection in the following format;
Name                                                                                                     Description
——-                                                                                                       —————
{ABCEF123-AB12-3333-AB23-42D619CB3456}#Template1   This is site template 1
{BDFED456-D416-4739-9FC4-32E619CB5678}#Template2    This is site template 2
{3CEC44D4-D413-6789-9FC9-52F619CB6789}#Template3     This is site template 3

8.     Make a note of the Name including the { and } symbols of the template that you wish to use, this will be the “template id” that will be referenced in the workflow in Part II of this blog series.

That’s the first step complete, Part II we will deal wth creating the workflow.

About the author