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

$clientid = "abc-abc-abc-abc-abc" #Add client id of site

$clientsecret = "abcdefghijklmnopq=" #Add client secret of site

$listname  =  "Employee"

########################################################

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

Popular posts from this blog

SharePoint online - 'Load More' button click event to show more items using PnPjs

SPFx - Display export buttons for Excel, CSV, PDF, Copy, Print, Column visibility in Datatable.net using Typescript

Rest API for Delete Yammer Comments