Get And Apply PnP Template Of A Specific List Or Library Using PnP Provisioning Engine

This blog will show how to get a PnP template of a specific SharePoint list or document library and apply to another site collection using PnP provisioning engine.
 
Using PnP provisioning you can model a site by configuring the design of site columns, content types, list definitions and instances, composed looks, pages (either web part pages or wiki pages), and much more, via your web browser. When you are done with the design, you can export what you have done into a persistent provisioning template format.
 
PnP template is an XML file that contains a description of SharePoint elements (lists, libraries, pages, etc.) that will be created. You can create your own XML template for your SharePoint list or libraries. Then you can apply that template to as many target sites as you like.
 
The script below will help you to get a template of a specific list or library.
  1. Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/MySite  
  2. $listTitle = Read-Host "Enter title of the list or library"  
  3. $outputTemplateFile = "ListTemplate.xml";  
  4. $template = Get-PnPProvisioningTemplate -OutputInstance -Handlers Lists  
  5. $listTemplate = $template.Lists | Where-Object { $_.Title -eq $listTitle }  
  6. $template.Lists.Clear()  
  7. $template.Lists.Add($listTemplate)  
  8. Save-PnPProvisioningTemplate -InputInstance $template -Out $outputTemplateFile  
Once you execute the script, you will have the template for your specific list or document library.
 
To apply the generated template back to another site you just need to run the "Apply-PnPProvisioningTemplate" cmdlet.
 
The script below will help you apply the template to another site.
 
Connect-PnPOnline-Url - https://tenant.sharepoint.com/sites/OtherSite
 
Apply-PnPProvisioningTemplate-PathListTemplate.xml