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.

Migrate SharePoint lists using PnP PowerShell

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

  1. Start by opening the PowerShell console in your computer
  2. Copy the script below and update the variables $siteCollection, $templateName, $saveTemplateLocation and $listName
    $siteCollection = ""
    $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 ''
  3. 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
  4. Migrate SharePoint lists using PnP PowerShell

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

  1. With the PowerShell console open, copy the script below
  2. Update the variables $siteCollection and $templateFileLocation with your own values
    $siteCollection = ""
    $templateFileLocation = "C:\Users\JOAO\Desktop\template.xml"
    Connect-PnPOnline -Url $siteCollection -Interactive
    Invoke-PnPSiteTemplate -Path $templateFileLocation
  3. 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.

Migrate SharePoint lists using PnP PowerShell

No comments yet

Leave a Reply

I've been working with Microsoft Technologies over the last ten years, mainly focused on creating collaboration and productivity solutions that drive the adoption of Microsoft Modern Workplace.