How to Upload List Template to SharePoint Online using PowerShell?

Requirement: Import List Templates in SharePoint Online using PowerShell.

Why do we need list templates in SharePoint Online? Well, If you have a list with a set of columns and customization in SharePoint Online, You can reuse it in any other site collection without re-creating the list again from scratch. A list template contains fields, formulas, formatting, and optional data. List Templates can be downloaded and uploaded to other sites. In this tutorial, we will guide you through the process of importing a list template in SharePoint Online, so you can start using it on your SharePoint site.

SharePoint Online List Template Gallery URL
List template gallery in SharePoint Online URL:

How to import a List Template in SharePoint Online?

SharePoint list templates can be used to quickly create new lists or libraries with the same structure and content as an existing list or library. Importing a list template allows you to reuse a pre-designed collection of settings, views, and data in a new list or library. This feature can save time and effort in creating new lists or libraries, as you don’t have to manually create each one from scratch.

List templates (.STP) downloaded should be uploaded to any site collection’s list template gallery in order to reuse. Here is how to upload a list template to SharePoint Online:

  1. Go to Settings >> Site settings page >> Click on “List templates” under Web Designer Galleries (List Template Gallery is Missing in SharePoint Online? Here is the fix: List Template Gallery is not available in SharePoint Online?)
  2. Click on the “Upload” button from the Files tab of the ribbon how to import list template in sharepoint online
  3. Upload the .stp file that you downloaded from the site collection. upload list template sharepoint online powershell
  4. Provide a Name and Title to the Template and Hit Save.
    import list template to sharepoint online

Now, your list template should be available as an APP in the site collection you uploaded the list template. Let’s see SharePoint Online PowerShell to upload the list template.

Upload List Template in SharePoint Online using PowerShell

Here is how to import a list template in SharePoint Online using PowerShell:

#Load SharePoint CSOM Assemblies
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"

#Function to Upload a list template To SharePoint Online using powershell
Function Upload-SPOListTemplate
        [string]$SiteURL  = $(throw "Enter the Site URL!"),
        [string]$ListTemplateName = $(throw "Enter the List Template Name!"),
        [string]$ListTemplateFile = $(throw "Enter the File Name to Upload List Template!")
    Try {
        #Get Credentials to connect
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
        #Get the "List Templates" Library
        $List= $Ctx.web.Lists.GetByTitle("List Template Gallery")
        $ListTemplates = $List.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery()) 

        #Check if the Given List Template already exists
        $ListTemplate = $ListTemplates | where { $_["TemplateTitle"] -eq $ListTemplateName }

        If($ListTemplate -eq $Null)
            #Get the file from disk
            $FileStream = ([System.IO.FileInfo] (Get-Item $ListTemplateFile)).OpenRead()
            #Get File Name from source file path
            $TemplateFileName = Split-path $ListTemplateFile -leaf
            #Upload the File to SharePoint Library
            $FileCreationInfo = New-Object Microsoft.SharePoint.Client.FileCreationInformation
            $FileCreationInfo.Overwrite = $true
            $FileCreationInfo.ContentStream = $FileStream
            $FileCreationInfo.URL = $TemplateFileName
            $FileUploaded = $List.RootFolder.Files.Add($FileCreationInfo)
            #Set Metadata of the File
            $ListItem = $FileUploaded.ListItemAllFields
            $Listitem["TemplateTitle"] = $ListTemplateName
            $Listitem["FileLeafRef"] = $ListTemplateName
            #Close file stream

            write-host -f Green "List Template '$ListTemplateFile' Uploaded to $SiteURL"
            Write-host -f Yellow "List Template '$ListTemplateName' Already Exists"
    Catch {
        write-host -f Red "Error Uploading List Template!" $_.Exception.Message

$SiteURL = ""
$ListTemplateName= "Projects Template V4"
$ListTemplateFile = "C:\Temp\CrescentProject.stp"

#Call the function to Download the list template
Upload-SPOListTemplate -SiteURL $SiteURL -ListTemplateName $ListTemplateName -ListTemplateFile $ListTemplateFile

This uploads the list template to SharePoint Online using PowerShell. To upload a list template to SharePoint Online, use: SharePoint Online PowerShell to Upload a List Template

How to upload a List Template to Multiple Sites from a CSV File?

Say, you have a CSV file with a list of site URLs and want to upload the list template to all sites in the CSV file. Well, here is how to deploy list definitions STP to SharePoint Online using PowerShell.

upload list template to multiple sites from CSV file

Just replace this script from Line#75 in the above script.

#Read CSV file
$CSVData = Import-CSV "C:\Temp\sites.csv" -Header SiteURL

#Iterate through each row
ForEach($Row in $CSVData)
    Write-host "Uploading to Site:"$Row.SiteURL
    #Call the Function to upload list template to site        
    Upload-SPOListTemplate -SiteURL $Row.SiteURL -ListTemplateName $ListTemplateName -ListTemplateFile $ListTemplateFile

Last but not least: You must enable custom scripting to enable the “List template” on your site: How to Enable Custom Scripting in SharePoint Online?


By following the steps outlined in this tutorial, you will be able to import a list template in SharePoint Online, and start using it to create new lists or libraries with the same structure and content as the original. This feature can save time and effort in creating new lists or libraries, and help you maintain a consistent structure and content throughout your SharePoint site.

Once the list templates are uploaded, you can create new instances of the lists from the template either from the web browser interface or with PowerShell: How to Create a List from Template in SharePoint Online?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

5 thoughts on “How to Upload List Template to SharePoint Online using PowerShell?

  • I was able to import the .STP file using the PowerShell script for Discussion Board in SharePoint 2016 classic. However, it’s not showing any additional metadata that it should have read from the template file like, Created By (it is showing my name on all the posts), Latest reply by and actual replies. Also, when I add a new discussion it will allow me to do so but users cannot reply to it for see the contents after clicking on it.

  • Hi Salaudeen, great article, saved me a lot of time researching. One other question, how do you read from a CSV file with a list of all SPO sites where the template is to be uploaded? some steps will be useful as I am not a programmer. thank you. Sabs

  • I can’t find powershell command to save list instance as list template (to stp file) or export to stp file?

    i tried this from Microsoft as well,

    need your advice


Leave a Reply

Your email address will not be published. Required fields are marked *