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.
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.