Introduction:
With SharePoint becoming an integral part of businesses, a frequent challenge faced by many is exporting and importing sets of SharePoint lists while maintaining their lookup data. With the advent of the PowerShell commands and especially the export-pnplisttositetemplate, this task has been streamlined. In this guide, we’ll dive deep into how to seamlessly perform these operations.
Many developers and app builders prefer SharePoint as their database choice. The primary reason is that those with Microsoft 365 licenses can utilize SharePoint without the need for any extra licenses. A common scenario they encounter is the need to transfer objects between different sites or even different organizations. Using PowerShell scripts combined with the PnP Framework and Provisioning Engine, this becomes feasible.
In this detailed guide, we will walk you through the process of exporting and importing sets of SharePoint lists. We will also ensure the lookup data remains intact. Not only that, but you’ll also get a glimpse into the structure of the scripts, which can serve as a foundation for creating scripts for creating SharePoint lists.
Steps to Export Parent and Child Lists with Data:
For exporting a set of SharePoint lists, the PnP Framework combined with the Provisioning Engine is invaluable. Below are the necessary PowerShell commands:
# Connect to the source SharePoint site Connect-PnPOnline -Url "https://sourceSite.sharepoint.com/sites/sourceSite" # Export the source lists Export-PnPListToSiteTemplate -Out "C:\Apps\SharePoint\myListExport.xml" -List "BuildingType", "Building" # Export the data for the selected lists Add-PnPDataRowsToSiteTemplate -Path "C:\Apps\SharePoint\myListExport.xml" -List "BuildingType" Add-PnPDataRowsToSiteTemplate -Path "C:\Apps\SharePoint\myListExport.xml" -List "Building"
For detailed documentation on the Export-PnPListToSiteTemplate and Add-PnPDataRowsToSiteTemplate, feel free to visit the official Microsoft documentation.
Creating a Script for Lists with Lookup Data:
Post the above process, an XML template file is generated at the specified location. This file houses the definition of the lists in question, including field name definitions, and the script that stipulates the data rows in the lists.
Importing Lists to a Destination SharePoint Site:
To populate our target site with the SharePoint lists and data, we first need to store the script in an accessible location on our system. Once done, with the help of PowerShell and specific cmdlets, the import can be executed.
# Connect to the destination SharePoint site Connect-PnPOnline -Url "https://destinationSite.sharepoint.com/sites/destinationSite" # Import the items from the template file Invoke-PnPSiteTemplate -Path "C:\Apps\SharePoint\listImports.xml"
After executing the above, you can access the destination SharePoint site and inspect the imported lists and records.
Conclusion:
The need for exporting and importing sets of SharePoint lists while ensuring the integrity of lookup data is frequent and crucial. Leveraging PowerShell commands and the PnP Framework makes this task efficient and hassle-free. This guide aimed to shed light on the process, hoping to make your SharePoint experience smoother.
If you require any further assistance or have any technical inquiries, please don’t hesitate to contact us. Our team is always ready to assist and provide the solutions you need.