How to migrate lists using PnP PowerShell
Lists migration in SharePoint and Microsoft Lists is the process of moving lists from one site or tenant to another one.
Migrations can be necessary for a variety of reasons, including upgrading an existing intranet, merging multiple site collections, or consolidating data from different sites. The migration process can be complex and time-consuming, as it requires careful planning and execution to ensure that all data is accurately transferred and that there is no loss or corruption of information.
Thanks to PnP PowerShell simple migrations like moving a list from one site collection to a another one or even to a new tenant is relatively simple as explained below.
In order to accomplish the steps described in this article you must install the latest version of the PnP PowerShell module, more information about how to do it can be found here.
Save a list as a template with all its content
- Start by opening the PowerShell console in your computer
- Copy the script below and update the variables $siteCollection, $templateName, $saveTemplateLocation and $listName
$siteCollection = "https://contoso.sharepoint.com/sites/ProjectX" $saveTemplateLocation = "C:\Users\JOAO\Desktop\" $templateName = "template" $listName = "ACE Cards" Connect-PnPOnline -Url $siteCollection -Interactive $siteTemplate = Get-PnPSiteTemplate -IncludeAllClientSidePages -Handlers Lists -ListsToExtract $listName -Out ("{0}{1}.xml" -f $saveTemplateLocation, $templateName) Add-PnPDataRowsToSiteTemplate -path ("{0}{1}.xml" -f $saveTemplateLocation, $templateName) -List $listName -Query '
' - Execute the script and wait for it to finish, the process may take some time depending on the number of items you have in the list. If you don’t want to migrate the content of the list and just want its definition remove the cmdlet Add-PnPDataRowsToSiteTemplate from the template
Once the process finishes you will get an XML file containing the definition of your list and its items.
Deploy a list from template using PnP PowerShell
- With the PowerShell console open, copy the script below
- Update the variables $siteCollection and $templateFileLocation with your own values
$siteCollection = "https://contoso.sharepoint.com/" $templateFileLocation = "C:\Users\JOAO\Desktop\template.xml" Connect-PnPOnline -Url $siteCollection -Interactive Invoke-PnPSiteTemplate -Path $templateFileLocation
- Execute the script and wait for it to finish
To check the success of the list migration, go to the site where you just deployed the list and open it.
No comments yet