In this tutorial, we will discuss how to save list as a template in SharePoint using PowerShell. It will work in SharePoint 2013/2016 as well as SharePoint 2019. Also, we will see how to save list as template in SharePoint Online using PowerShell and using PnP PowerShell.
The code I have used in SharePoint 2016 site, but will work in SharePoint 2013 as well as in SharePoint 2019 as well.
You can run the PowerShell script in PowerShell ISE.
$templateFileName="Product Template File Name" $templateName="Product Template" $templateDesc="Use this template to create product list" $includeContent=$true $web = Get-SPWeb "http://mypc/sites/MySP2016SiteCollection/" $List = $web.Lists["Products"] $List.SaveAsTemplate($templateFileName, $templateName, $templateDesc, $includeContent)
Here, you can provide the list template name, template file name, list template description.
Also, if you want to include the content, then you can make it to true.
Once you run the script, it will create the list template and stored in the SharePoint site list template gallery.
Now, we will see how to create a list by using the SharePoint list template which we have already created before.
$listname="New List Name" $web = Get-SPWeb "http://mypc/sites/MySP2016SiteCollection/" $listTemplates = $site.GetCustomListTemplates($web) $web.Lists.Add($listname, $listTemplates["Product Template"])
This will create a new list name as “New List Name” in the SharePoint 2013/2016/2019 site.
If you are using a modern SharePoint Online site, then there is an option we can create a list from an existing list. I have written a detailed blog post, how to create a list from the existing list in SharePoint Online.
You can also use the browser to save list as template in classic SharePoint Online site.
Open the SharePoint list, go to the list settings.
From the list settings page, click on “Save list as template“.
Then it will ask you to provide the File name, Template name, Template description like below:
Also, if you want to include the list content, then click on “Include Content” like below:
Once you click on OK, the list template will be saved in the list template gallery in SharePoint Online or SharePoint 2013/2016/2019.
You can see the list template in the list template gallery in the SharePoint site.
This is how we can save list as template in SharePoint Online or SharePoint 2013/2016/2019.
Here, I have used the below client side dlls.
If you are using Windows 10 laptop, then you can use the SharePoint Online client side component SDK.
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://tsinfo.sharepoint.com/sites/TSInfoClassic/" $username = "firstname.lastname@example.org" $password=ConvertTo-SecureString "***********" -AsPlainText -Force $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl) $credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $password) $ctx.Credentials = $credentials $list = $Ctx.Web.lists.GetByTitle("Products") $list.SaveAsTemplate("Product Template File Name", "Product Template Name", "This is the product list template description", $true) $ctx.ExecuteQuery()
Once you execute the above PowerShell script, the SharePoint Online list template like below:
PnP PowerShell is very easy to work with SharePoint Online.
Now, we will see how to save list as template in SharePoint Online using PnP PowerShell.
Connect-PnPOnline -Url "https://tsinfo.sharepoint.com/sites/TSInfoClassic/" -Credentials (Get-credential) $context = Get-PnPContext $list = Get-PnpList -Identity "Products" $list.SaveAsTemplate("PnP Product List Template Filename", "PnP Product List Template", "This list template is created using PnP", $true) $context.ExecuteQuery()
Once you execute the code, it will ask you to enter the credentials and then it will Save the list as template in SharePoint.
This is how to save list as template SharePoint Online using PnP PowerShell.
We can extract a .stp file and then how we can make a .stp file from the extracted files in SharePoint. We have created a custom list template which usually saves as a .stp file. After saving this .stp file we wanted to modify something in the manifest.xml file
First, you can extract the .stp file. Here I have used 7-Zip to extract it like below:
Once it is successfully extracted, you can see the manifest.xml file.
Then you can modify the file using Notepad or Notepad++ (any editor you can use). Once the modification over we can run the below command to create the .stp file again.
Here I have kept the manifest.xml file in the d drive and running the below command.
makecab.exe manifest.xml WorkflowMailTemplates.stp
This is how to extract .stp file and make .stp file in SharePoint Online and how to change in manifest.xml file in SharePoint.
You may like:
- PowerShell Copy Item examples
- Save list as template missing in SharePoint Online modern team site
- Create a Custom Document Template from SharePoint List using Microsoft Flow
- How to check which site template used in SharePoint Online Site using JSOM
- Add multiple Office templates as content type to a document library in SharePoint Online
- The list is too large to save as a template. The size of a template cannot exceed 52428800 bytes error in SharePoint Online/2016/2013
In this SharePoint tutorial, we learned how to save list as template in SharePoint Online using PowerShell and PnP PowerShell.
Also, we will see how to save a list as template in SharePoint 2013/2016 or SharePoint 2019, or SharePoint Online.
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site EnjoySharePoint.com