Creating a List Template on SharePoint Online from the Web Interface and Using PowerShell Script

Yunus Emre Araç
4 min readApr 17, 2024

--

Referance: https://www.yunusemrearac.com/2024/04/17/sharepoint-online-uzerinde-liste-sablonunu-web-arayuzunden-ve-powershell-script-kullanarak-olusturmak/

Hello friends, today I will show you how to use the “Save list as Template” feature in the list setting on SharePoint from the web interface and with a powershell script.

First, let me show you how to use this feature in the web interface on Sharepoint Online.

We come to the Sharepoint list that we want to backup from, and while in the list, we open the settings menu by clicking on the “Settings” icon in the ribbon at the top right. Here, we go to the settings page of the existing list by clicking on the “List settings” sub-link under the main heading “SarePoint” in the headings.

When we come to the list setting page, we click on the “Save list as template” menu under the general heading “Permissions and Management” in the settings headings here and we go to the save list template screen.

On the screen that opens, we write the name of our file in the “File name” section. We need to write the name and description of the template we will purchase in the “Template name” and “Template description” sections. If you want the data in the existing list to be included in this template, you must select the checkbox option that says “Include Content”. After making the necessary adjustments, you can start the template saving process by pressing the “OK” button.

NOTE: If you want to include the data in the list in the template, it has a certain size. If there is a large number, it will not be included and will give an error.

If your template import process is completed without any problems, you will see a screen informing you that the process has been completed successfully. In this section, if you want, you can click “list template gallery.” You can return to the gallery list by clicking on the link, or you can return to the settings page by completing the process by clicking “OK”. If you want, you can go to the template gallery from the site settings or with the address extension “_catalogs/lt/Forms/AllItems.aspx”.

If you want to do this backup process with a powershell script, you can use the powershell script below.

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"

$SiteURL="https://yunusemrearac.sharepoint.com/"
$ListName="yunusemrearac"

$FileName="yunusemrearacListTemplate"
$TemplateName="yunusemrearacListTemplate"
$Description ="yunusemrearac List Template"
$IncludeData = $True

Try{
$Cred= Get-Credential

$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

$List = $Ctx.Web.lists.GetByTitle($ListName)
$List.SaveAsTemplate($FileName, $TemplateName, $Description, $IncludeData)
$Ctx.ExecuteQuery()

Write-Host -f Green "List Saved as Template!"
}
Catch {
write-host -f Red "Error Saving List as template!" $_.Exception.Message
}

You need to define the “SiteURL, ListName, FileName, TemplateName, Description, IncludeData” parameters in the above powershell script as you wish, according to your sharepoint site and the settings I mentioned above.

In addition, if you wish, you can perform this process by using the PnP Powershell script below.

$SiteURL= "https://yunusemrearac.sharepoint.com/"
$ListName = "yunusemrearac"
$TemplateFileName = "yunusemrearacListTemplate.stp"
$TemplateName = "yunusemrearacListTemplate"
$TemplateDescription="yunusemrearac List Template"
$IncludeData = $True

Connect-PnPOnline -Url $SiteURL -Credentials (Get-credential)
$Context = Get-PnPContext

$List = Get-PnpList -Identity $ListName

$List.SaveAsTemplate($TemplateFileName, $TemplateName, $TemplateDescription, $IncludeData)
$Context.ExecuteQuery()

Likewise, you need to define the “SiteURL, ListName, FileName, TemplateName, Description, IncludeData” parameters in the pnp powershell script as you wish, according to your sharepoint site and the settings I mentioned above.

If you define and run the scripts and parameters correctly, the scripts will run without errors and save your backup to the template gallery.

--

--

Yunus Emre Araç
Yunus Emre Araç

Written by Yunus Emre Araç

Technology Product Manager of Corporate Applications at ING | Old Microsoft Student Partners Lead | İnönü Üniv. Bilg. Müh. | İAU Bilg. Müh. Tezli Yüksek Lisans