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).
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
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
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.
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.
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).
I get an exception when passing the $ListCreation object to the lists add method:
======
Exception calling “Add” with “1” argument(s): “The object is not associated with an object identity or the object
identity is invalid.”
======
The $ListCreation object has the following properties and seems to be valid. Any thoughts?
======
CustomSchemaXml :
DataSourceProperties : {}
Description :
DocumentTemplateType : 0
ListTemplate : Microsoft.SharePoint.Client.ListTemplate
QuickLaunchOption : Off
TemplateFeatureId : 00bfea71-de22-43b2-a848-c05709900100
TemplateType : 100
Title : Custom List From Template
Url :
TypeId : {e247b7fc-095e-4ea4-a4c9-c5d373723d8c}
======
Hi Are, I just want to say thanks for this, very useful.
I just have an issue as reported by others where the library is being created but is empty and does not contain any of my custom columns. If I try to add the $listcreation.ListTemplate property, I get an error stating it is not valid. Everything else works and if I create it via the SharePoint UI (add an app) and select the same template, it works fine. Any idea why?
I am using SharePoint PnP PowerShell 2016 for on premise and have updated my module to the latest version.
Thanks
Hi Are, any update on creating the list with layout and content. I’m experiencing same symptoms list is created empty and no configuration of fields/views.
Thanks a lot.
In case anyone else hits a similar issue – when using an STP, providing a URL and a Title, the URL is ignored, and so your URL ends up being the title – see https://github.com/SharePoint/PnP-Sites-Core/issues/1806