SharePoint Online: Create List from Custom Template using PowerShell

Requirement: Create a List from Custom List Template using PowerShell in SharePoint Online.

SharePoint Online: How to Create List from Template?

List templates in SharePoint Online save a lot of time by reusing any existing list or document library, which comprises all columns and, optionally, the data from the list. You can create any number of copies from the list template.

Assuming you have an existing list template on the site, Here is how to create a list from a template SharePoint Online:

  1. Login to your SharePoint Online site >> Click on the Settings gear icon and click “Add an app.”
  2. You can use pagination to find your list template or the “Find an App” search box to pick your list template. sharepoint online create list from custom template
  3. Provide a name to your new list and click on “OK”. This creates a new list from the template in SharePoint Online.
  4. You will see a new list created with the same list schema and also data if you have selected “Include Content” when creating the list template initially. Let’s see the SharePoint Online PowerShell to create a list from the template.

SharePoint Online: Create a List from Template using PowerShell

Lists are the primary building blocks SharePoint uses to store information. Let’s use PowerShell in SharePoint Online to create a list from a template.

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

#Config Variables
$SiteURL="https://crescent.sharepoint.com"
$ListTemplateName = "Quick Links Template"
$ListName="Quick Links V2"

#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 All Lists
$Lists = $Ctx.Web.Lists
$Ctx.Load($Lists)
$Ctx.ExecuteQuery()

#Get the Custom list template
$ListTemplates=$Ctx.site.GetCustomListTemplates($Ctx.site.RootWeb)
$Ctx.Load($ListTemplates)
$Ctx.ExecuteQuery()

#Filter Specific List Template
$ListTemplate = $ListTemplates | where { $_.Name -eq $ListTemplateName } 
If($ListTemplate -ne $Null)
{
    #Check if the given List exists
    $List = $Lists | where {$_.Title -eq $ListName}
    If($List -eq $Null)
    {
        #Create new list from custom list template
        $ListCreation = New-Object Microsoft.SharePoint.Client.ListCreationInformation
        $ListCreation.Title = $ListName
        $ListCreation.ListTemplate = $ListTemplate
        $List = $Lists.Add($ListCreation)
        $Ctx.ExecuteQuery()
        Write-host -f Green "List Created from Custom List Template Successfully!"
    }
    else
    {
        Write-host -f Yellow "List '$($ListName)' Already Exists!"
    }
}
else
{
    Write-host -f Yellow "List Template '$($ListTemplateName)' Not Found!"
}

The same method applies to creating a document library from a custom template.

SharePoint Online: PnP PowerShell to Create List from Template

Lists are the primary building blocks for storing information in SharePoint. Here is the PnP PowerShell to create a list from the template:

#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ListName = "Migation Tasks"
$ListTemplateName ="Project Tasks"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Custom List Template
$Ctx = Get-PnPContext
$Web = Get-PnPWeb
$RootWeb = $Ctx.Site.RootWeb
$ListTemplates = $Ctx.Site.GetCustomListTemplates($RootWeb)
$Ctx.Load($RootWeb)
$Ctx.Load($ListTemplates)
Invoke-PnPQuery
$ListTemplate = $ListTemplates | where {$_.Name -eq $ListTemplateName}
 
#sharepoint online powershell create list from template
$ListCreation = New-Object Microsoft.SharePoint.Client.ListCreationInformation
$ListCreation.Title = $ListName
$ListCreation.ListTemplate = $ListTemplate
$Web.Lists.Add($ListCreation)
Invoke-PnPQuery

Following the steps outlined in this article, you can create a new list from a pre-built template, customize the list to meet your specific needs, and start adding data to the list.

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!

13 thoughts on “SharePoint Online: Create List from Custom Template using PowerShell

  • Salaudeen Rajack, this is great ! Thank you for sharing.

    When I try to use the example at the bottom (SharePoint Online: PnP PowerShell to Create List from Template) in a site that was created with the Communication template, the script fails at line#15 Invoke-PnPQuery. It says it can’t find the template. Have you experienced this problem and how do you workaround it?

    The script works perfectly when I use it in a SP site created with the Team Site template

    Thanks again Guillermo

    Reply
    • Well, that’s because I have a custom list template “Project Tasks” and the script tries to create a new list instance from it. In your case, You may not have the “Project Tasks” template in your site collection.

      Reply
  • How can I create the list, in specific URL, I have “https://XXXX.sharepoint.com/sites/SEAS/DOAS” but the list was created in the root subsite “https://coopelescaea.sharepoint.com/sites/SEAS”,

    how can i manipulate the url in this part… “$Web = $Ctx.Site.RootWeb” …. thanks

    Reply
  • How to create library from a custom template in subsite using pnp, as the above one creates it in the parent site only even after connecting to subsite!!!

    Reply
  • I am getting the below error when run PnP script: Please help to fix it

    Cannot convert argument “parameters”, with value: “Microsoft.SharePoint.Client.ListCreationInformation”, for “Add”
    to type “Microsoft.SharePoint.Client.ListCreationInformation”: “Cannot convert the
    “Microsoft.SharePoint.Client.ListCreationInformation” value of type
    “Microsoft.SharePoint.Client.ListCreationInformation” to type “Microsoft.SharePoint.Client.ListCreationInformation”.”
    At line:22 char:1
    + $Web.Lists.Add($ListCreation)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [], MethodException
    + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument

    Reply
  • When I run this, I get an error kicked back stating that the term ‘else’ is not recognized as the name of a cmdlet, function, etc. etc. I was able to fix this by correcting what looks like an error with a bracket (see below). My issue is now even though the script runs, it doesn’t actually create the list or do anything. Any ideas?

    else
    {
    Write-host -f Yellow “List ‘$($ListName)’ Already Exists!”
    }
    else
    {
    Write-host -f Yellow “List Template ‘$($ListTemplateName)’ Not Found!”
    }
    }

    Reply
    • Looks you have copied the script partially! Confirmed this script works just fine.

      Reply
    • Figured it out. It was simple mistake of not saving the list to the list gallery. It does still throw an error around the multiple else commands, but works in spite of that.

      Reply
    • Separate question. If I wanted to modify this script to bulk create lists based on a list of names from a text file, what would be the best way to go about it?

      Reply
  • It failed when I try to create a template from English language site and list instance at German language site! script did not create list instance on German language site. Please help!

    Reply
    • You need to rename the .stp to .cab, Open the “manifest.xml” inside and change the language ID and re-pack the STP with “makecab manifest.xml template.stp”

      Reply

Leave a Reply

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