Introduction
While moving the configuration lists from Dev/SIT to UAT/Prod, moving the list data is kind of a problem, which we can automate, using PnP-Powershell script.
Please follow the steps given below.
While moving the configuration lists from Dev/SIT to UAT/Prod, moving the list data is kind of a problem, which we can automate, using PnP-Powershell script.
Please follow the steps given below.
Step 1
Connect to Source and Destination tenant.
Connect to Source and Destination tenant.
#Pass the UserID and Password to connect the source and destination SharePoint O365 sites.
Source
Source
- $username = "userid1"
- $userPassword = "password1"
- $secpasswd = ConvertTo-SecureString $userPassword -AsPlainText -Force
- $mycreds = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $secpasswd
Destination
- $username1 = "userid2"
- $userPassword1 = "passw0rd2"
- $secpasswd1 = ConvertTo-SecureString $userPassword1 -AsPlainText -Force
- $mycreds1 = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username1, $secpasswd1
Step 2
Read the list data from the source list and write it in the destination list.
Read the list data from the source list and write it in the destination list.
Get the Souce context
- $webUrl1 = "https://tenant2.sharepoint.com/saurabh/"
- Write-Output $("Connecting to {0}..." -f $webUrl);
- Connect-PnPOnline -Url $webUrl -Credentials $mycreds;
- Write-Output "Context obtained";
Function to read the data from source list and write it in the destination list
- function GetSetListItems() {#
- Input Parameters
- $listName = "Configuration List"
- $fields = "Title", "Color_x0020_Code"#
- Retrieves items
- $listItems = Get - PnPListItem - List $listName - Fields $fields# Write lists item to other list
- Connect - PnPOnline - Url $webUrl1 - Credentials $mycreds1;
- foreach($listItem in $listItems) {
- $itemValues = @ {
- "Title" = $listItem["Title"];
- "Color_x0020_Code" = $listItem["Color_x0020_Code"]
- }
- Add - PnPListItem - List $listName - Values $itemValues
- }
- }
I hope, this will solve the problem of migrating the lists data from one tenant to other tenant. You can also copy the list data on same tenant.

Germaine BoltonPosted Apr 12, 2024, 3:20 AM
Great job. This worked great for me. Also, simply pulling the title only filled in all other fields in the destination list. I didn't have to explicitly list each. Thanks. great job.
Bharat Bhushan KvPosted Apr 12, 2020, 8:39 AM
Can you give it for Batch wise List Items Copy without including the Field Names from the list manually ??