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 optionally data as well. List Templates can be downloaded and uploaded to other sites. Here is how to use list template SharePoint Online:

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

How to import a List Template in SharePoint Online?

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:

  • 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?)
  • Click on the “Upload” button from the Files tab of the ribbon
    how to import list template in sharepoint online
  • Upload the .stp file that you downloaded from the site collection.
    upload list template sharepoint online powershell
  • Provide a Name to 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 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?

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

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

  • 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