How to export SharePoint List Template using PnP PowerShell?

Summary

I occasionally need to duplicate SharePoint List Definition from one site to other or some time create a new list from the existing list.

PnP.PowerShell can rescue using the Template methods.

Get-PnPSiteTemplate

Save-PnPSiteTemplate

Invoke-PnPSiteTemplate

Using the Get-PnPSiteTemplate you can the template definition in the XML. Using the Save-PnPsitetemplate you can save the template definition into the local file system.

Using the Invoke-PnPSiteTemplate you can use the local file system template definition file to a brand new site or same site with new list.

Step By Step

#1 Install Pnp.PowerShell Power Shell Module. Refer this article.

#2 Using the SharePoint App register pages register an app. Refer this article.

#3 Execute the following script block.



$HashArgs = @{
    url = "https://{YOUR TENANT}.sharepoint.com/sites/{YOUR SITE}"
    ClientId = "{ID FROM STEP #2}"
    ClientSecret = "{SECRET FROM STEP # 2}"
}

$conn = Connect-pnpOnline @HashArgs -ReturnConnection

# The script below will help you to get a template of a specific list or library.
$listTitle = Read-Host "Enter title of the list or library"  
$outputTemplateFile = $("{0}ListTemplate.xml" -f  $listTitle)
$template = Get-PnPSiteTemplate -OutputInstance -Handlers Lists  
$listTemplate = $template.Lists | Where-Object { $_.Title -eq $listTitle }  
$template.Lists.Clear()  
$template.Lists.Add($listTemplate)  
Save-PnPSiteTemplate -InputInstance $template -Out $outputTemplateFile

Conclusion

Using the above method you can save template for a specific list and using Invoke-PnPSiteTemplate create the same list again.

About Pankaj

I am a Developer and my linked profile is https://www.linkedin.com/in/pankajsurti/
This entry was posted in Uncategorized. Bookmark the permalink.

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 )

Facebook photo

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

Connecting to %s