SharePoint Online - Save a modern SharePoint list as a template
Requirement : To save a modern SharePoint list as a template to xml file to add in update.xml or as a backup AND it was very handy to copy list definition and even to migrate lists with its content..
You will need to manually define all the columns that you want to extract with data as shown in the example below. Here is the script:
########################################################
$targetWeb = "https://your-site.sharepoint.com/sites/collection/" ## URL of the site
########################################################
try
{
Connect-PnPOnline -Url $targetWeb -AppId $clientid -AppSecret $clientsecret;
$clientContext = Get-PnPContext;
Write-Host "Connection to site established: " $targetWeb;
Export-PnPListToProvisioningTemplate -Out "c:/output.xml" -List $listname
#Add data to the provisioning template
Add-PnPDataRowsToProvisioningTemplate -Path c:/output.xml -List $listname -Query '<view></view>' -Fields "Title","Name","EmailID","IsActive"
}
catch
{
Write-Error $_
}
Comments
Post a Comment