Create list from custom template in SharePoint with PowerShell

This examples shows how to create new lists from custom list templates in SharePoint using PowerShell and CSOM. Custom list templates are STP-files uploaded to the List Template Gallery on the site. This should work both on-premises (2013/2016) and Online (Office 365).

Note: This example uses commands from the Office Dev PnP PowerShell library, ex. “Connect-PnPContext”. I recommend using this library for working this PowerShell and SharePoint (both Online and On-Premises).

5 Replies to “Create list from custom template in SharePoint with PowerShell”

  1. Hi,
    Thanks for this post.It is useful for creating the list with custom list template.
    I have tried to create a list with my custom list using a template.In my case the list is created successfully but without any column names and data.
    only title column is showing and other columns from my custom list template is not created and no data also.
    Please help me to create a list with same template.

    Thanks
    Poovi

  2. Try the following instead…

    $ListCreation = New-Object Microsoft.SharePoint.Client.ListCreationInformation
    $ListCreation.Title = $ListName

    ## Add Line Below ##
    $ListInfo.ListTemplate = $ListTemplate

    ## Optional / Good Practice ##
    #$ListCreation.TemplateFeatureId = $ListTemplate.FeatureId
    ## Optional / Good Practice ##
    #$ListCreation.TemplateType = $ListTemplate.ListTemplateTypeKind

    (See ListCreationInformation properties
    https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.listcreationinformation_properties.aspx)

    Obilogic

    1. Hi, there is something easier to do :
      You can replace THIS
      [ if ($ListTemplate -eq $null)
      {
      Throw [System.Exception] “Template not found”
      }

      $ListCreation = New-Object Microsoft.SharePoint.Client.ListCreationInformation
      $ListCreation.Title = $ListName
      $ListCreation.TemplateFeatureId = $ListTemplate.FeatureId
      $ListCreation.TemplateType = $ListTemplate.ListTemplateTypeKind

      $Web.Lists.Add($ListCreation)
      Execute-PnPQuery ]

      BY THIS cmdlet PnP :
      New-PnPList -Title $ListName -Url $ListName -Template $ListTemplate.ListTemplateTypeKind
      (I just tested and this works fine !)
      https://msdn.microsoft.com/en-us/pnp_powershell/newpnplist

      Title and Url can be different of course.

      1. Like Poovi, I can use the above to create a new list but it is empty of the fields that the saved list template has. The extra comments also fail to create the fields.

    2. Thanks, Obilogic. I have now tested this myself, and your suggested change makes this work as expected again.The script example is updated (change on line 29).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s