How to Copy Items from One List to Another in SharePoint Online Using PnP PowerShell?

One of my clients recently wanted me to copy items from one SharePoint Online list to another. PnP PowerShell is one of the best solutions for this. In this tutorial, I will show you how to copy items from one list to another in SharePoint Online using PnP PowerShell.

Copy Items from One List to Another in SharePoint Online using PnP PowerShell

This is a very common requirement among developers while working with items in a SharePoint Online list. No one uses a third-party tool for this, as it is expensive. So, we can use PnP PowerShell.

Here, I have created a SharePoint Online site which has a custom list having below three columns:

  • Title
  • Description
  • Quantity

I have also added bulk items to the SharePoint list. The list has more than 5000 items in it. You can see what the list looks like:

copy items from one sharepoint list to another

I have created the same list in another SharePoint Online site and now we will copy from the source list to the destination list in another SharePoint site.

Follow the below steps to copy items from one list to another list in SharePoint Online using PnP PowerShell.

  • Connect to the SharePoint Online Site: First, you need to connect to your SharePoint Online site using PnP PowerShell. Use the following command to connect:
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive

This command will prompt you to log in with your SharePoint Online credentials.

  • Get Items from the Source List: Next, retrieve the items from the source list. Replace “SourceList” with the name of your source list:
$sourceListItems = Get-PnPListItem -List "SourceList"
  • Copy Items to the Destination List: Now, loop through each item in the source list and add it to the destination list. Replace “DestinationList” with the name of your destination list:
foreach ($item in $sourceListItems) {
    Add-PnPListItem -List "DestinationList" -Values @{
        Title = $item["Title"]
        Description = $item["Description"]
        Quantity = $item["Quantity"]
    }
}

Here, you can see the complete PnP PowerShell script for copying items from one SharePoint Online list to another.

# Connect to SharePoint Online
Connect-PnPOnline -Url "https://szg52.sharepoint.com/sites/PowerPlatformFAQs" -Interactive

$sourceListItems = Get-PnPListItem -List "LargeInventoryList"
foreach ($item in $sourceListItems) {
    Add-PnPListItem -List "DestinationLargeInventoryList" -Values @{
        Title = $item["Title"]
        Description = $item["Description"]
        Quantity = $item["Quantity"]
    }
}

I executed the above PowerShell script, and it copied the items from the source list to the destination list.

Copy Items from One List to Another in SharePoint Online using PnP PowerShell

You can also see the destination SharePoint list with the copied items.

copy items from one list to another sharepoint

This is how to copy items from one list to another in the same SharePoint Online site using PnP PowerShell.

Copy List Items from One SharePoint Site to Another SharePoint Site using PnP PowerShell

In the above example, the source and destination list are both presented on the same SharePoint site.

Sometimes, you might get requirements to copy items from one SharePoint site to another SharePoint Online site. For those cases, you just need to modify the script like the below:

# Connect to the Source SharePoint Site
Connect-PnPOnline -Url "https://szg52.sharepoint.com/sites/PowerPlatformFAQs" -Interactive

# Retrieve Items from the Source List
$sourceListItems = Get-PnPListItem -List "LargeInventoryList"

# Connect to the Destination SharePoint Site
Connect-PnPOnline -Url "https://szg52.sharepoint.com/sites/PowerShellFAQs" -Interactive

# Copy Items to the Destination List
foreach ($item in $sourceListItems) {
    Add-PnPListItem -List "LargeInventoryList" -Values @{
        Title = $item["Title"]
        Description = $item["Description"]
        Quantity = $item["Quantity"]
    }
}

You can see the screenshot below; after I executed the above script, it copied the list of items from the source SharePoint site to the destination SharePoint site.

Copy List Items from One SharePoint Site to Another SharePoint Site using PnP PowerShell

Copy SharePoint Items from One List to Another Using PnP PowerShell (Batch Processing)

Below is a PnP PowerShell script to copy list items from one SharePoint list to another using the -PageSize 500 parameter to handle larger lists efficiently.

# Define variables
$sourceSiteUrl = "https://szg52.sharepoint.com/sites/PowerPlatformFAQs"
$targetSiteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
$sourceListName = "LargeInventoryList"
$targetListName = "LargeInventoryList"

# Connect to the source SharePoint site
Connect-PnPOnline -Url $sourceSiteUrl -Interactive

# Get list items from the source list with paging
$items = Get-PnPListItem -List $sourceListName -PageSize 500 -Fields "Title", "Description", "Quantity"

# Connect to the target SharePoint site
Connect-PnPOnline -Url $targetSiteUrl -Interactive

# Iterate through each item and add it to the target list
foreach ($item in $items) {
    $itemValues = @{
        "Title" = $item["Title"]
        "Description" = $item["Description"]
        "Quantity" = $item["Quantity"]
    }

    Add-PnPListItem -List $targetListName -Values $itemValues
}

This script ensures that large lists are handled efficiently by paging through the items in batches of 500.

I executed the above PowerShell script using VS code; you can see the output in the screenshot below.

Copy SharePoint Items from One List to Another Using PnP PowerShell

This is how to copy items from one large SharePoint list to another using PnP PowerShell batch processing.

Conclusion

In this tutorial, I have explained how to copy items from one SharePoint list to another using PnP PowerShell. I have also explained how to copy list items from one SharePoint site to another SharePoint site. We also saw how to copy items from large SharePoint list to another using PnP PowerShell.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.