Pnp-powershell: Add ability export a list or a document library as a template with contents (Get-PnPListProvisioningTemplate)

Created on 11 Feb 2018  路  8Comments  路  Source: pnp/PnP-PowerShell

Missing Feature | Enhancement

Add ability to selectively export a complete list or document library provisioning template.

Commandlet:
Get-PnPListProvisioningTemplate

Parameters:

  • List
  • Path (export template path)
  • IncludeDataRows
  • IncludeFiles (should save files and folders)
  • IncludeWebparts
  • IncludeContentTypes
  • IncludeFields
  • IncludeSecurity
  • IncludeColumnDefaults
  • IncludeValidationSettings
  • IncludeItemScheduling
  • IncludeMangedNavigationSettings
  • IncludeWorkflowSettings
  • IncludeEnterpriseMetadataSettings
  • IncludeInformationPolicySettings
  • IncludePropertyBagProperties
  • IncludeDataSetSettings

This functionality will allow to selectively export lists and document libraries along with all associated configurations.

Expected behavior

  • List or library should be exported with all available list settings (may require schema update).
  • All files or data rows shall be exported with all field values
  • Associated content types, webparts, workflows and other elements should be included in the template.

Actual behavior

N/A

Which version of the PnP-PowerShell Cmdlets are you using?

  • [x] PnP PowerShell for SharePoint 2013
  • [x] PnP PowerShell for SharePoint 2016
  • [x] PnP PowerShell for SharePoint Online

How did you install the PnP-PowerShell Cmdlets?

  • [ ] MSI Installed downloaded from GitHub
  • [x] Installed through the PowerShell Gallery with Install-Module
  • [ ] Other means

Most helpful comment

+1 for this request.

All 8 comments

Hi Ruslan,
Did you find a solution for this? does it resolved yet? Are we able to "save as a template" a custom list or library in Modern SP sites and then build new-list (library) based on our custom template in another SP team site (O365 group)?
Thanks

@ehsan-hakimi I proposed the enhancement, but I do not think any work has been done. My workaround is to export the whole site and selectively manually transfer elements of interest into the target template set. It takes time and human errors are common. But, it is doable. It would have been nice to have it automated because often we need to deploy incremental changes.

@ruslanurban Thanks so much, Yes I am deleting lines from template.xml now. Our scenario is even simpler. We just using OOTB modern team site and want to add one custom document library to it. Exactly the same action called "save list/library as a template" on SP 2013 and then deploy that template on a new sites collection.

+1 for this request. Also it would be great to have an ability to export lists/doclibs content also with Get-PnPProvisioningTemplate cmdlet.

+1 for this request.

Try to use this script to get a template of a specific list.
$listName - the name of the list.
$outputTemplateFileName - the location of output template file

$listName = "EmployeesTest999";
$outputTemplateFileName = "D:\Temp\template.xml";

$template = Get-PnPProvisioningTemplate -OutputInstance -Handlers Lists
$listTemplate = $template.Lists | Where-Object { $_.Title -eq $listName }
$template.Lists.Clear()
$template.Lists.Add($listTemplate)
Save-PnPProvisioningTemplate -InputInstance $template -Out $outputTemplateFileName

Thank you for your suggestion @antonkhrit. That is not exactly what I was looking for, and there are a few issues with this approach:

  1. ALL lists are exported first, and that is _not efficient_.
  2. ONLY list definition is exported, and it can be _easily located in a full site export_.
  3. Referenced site fields, content types, taxonomy items and other related objects are _NOT exported_.

Hi @ruslanurban,

I just demonstrated the way to extract specific artifacts from a template programmatically.

Not efficient, but you can wait some time to get a template. Not a big deal.

Only list definition is extracted in my case. This is just a general approach to extract specific entities from a template. You can modify the code to include more artifacts in a template.

For example, you can grab the template of the whole site, then remove only unnecessary lists and keep site fields, etc.

Your own workaround above is grabbing the whole template and removing not required entities manually. I did the same, but in a bit more elegant, programmatic way.

Still, a commandlet from PnP team that would allow us to do this, would be great.

Was this page helpful?
0 / 5 - 0 ratings