The movement of Lists and Libraries across sites is a common requirement that we come across in business scenarios. There are multiple ways to achieve this from using Custom Migration tools like ShareGate/Metalogix or we can use the native SharePoint Site Scripts and Site Templates (earlier Site Designs) to achieve this.
However, third-party tools come with their own cost, and Site Scripts have inherent limitations to migrated List content which leaves us with PnP Provisioning template as the most reliable choice when it comes to migrating list along with content.
In this article, we will see how we can use PnP Provisioning Engine to migrate List and Content across sites
We have a communication site for Department A that houses an inventory list with content that details the incoming and outgoing medicine details. As part of transferring ownership to Department B, we would like to migrate the List and its content to the new site location. We will see how we can do this using PnP Provisioning Template
We will initiate a connection to SharePoint online Site using the Connect-PnPOnline command and followed by that we will generate the Provisioning site template from the web where the list resides using the Get-PnPSiteTemplate command. The Out parameter will extract the template and output it as an Office Open XML file(with .pnp extension) or as a normal XML file in the specified location. To extract only a single list we will add the below parameters:
- Handlers : To extract only Lists in the web
- ListsToExtract : Specify the lists that needs to be extracted
By design, it will extract only the list schema, to extract the list content and update the already extracted template, we will use the command Add-PnPDataRowsToSiteTemplate
|Connect-PnPOnline -Url “https://office365journey.sharepoint.com/”|
Get-PnPSiteTemplate -Handlers Lists -ListsToExtract “Incoming Inventory” -Out “D:\Templates\template.pnp”
Add-PnPDataRowsToSiteTemplate -Path “D:\Templates\template.pnp” -List ‘Incoming Inventory’ -Query ‘<view></view>’
|$WebUrl = “https://office365journey.sharepoint.com/sites/2022CovidActions”|
$XMLPath = “D:\Templates\template.pnp”
Connect-PnPOnline -Url $WebUrl
Invoke-PnPSiteTemplate -Path $XMLPath
Thus we have extracted the list and the contents as a PnPProvisioning template.
So as to move the List via PnP Provisioning template to the new location, we will connect to the destination site again using the Connect-PnPOnline command with the new site URL .
We will then run the Invoke-PnPSiteTemplate to apply the PnP Template on the new site which will provision the list along with the content.
Heading over to the new SharePoint Site, we can see that the complete content has been moved to the newly provisioned list in the site.
Thus, we saw how to use the PnP Provisioning Template to migrate a single SharePoint List along with the content across the site. The complete PnP Provisioning options can be explored here and we will come up with another blog where we will explore a complete Site Provisioning process with PnP Provisioning templates