I have two Sharepoint sites, let's call them Business and Party for example.
The Business site has a list with 1000+ items. I want to copy the list items to the Party site. I want to do this in a repeatable, automated way.
I found that I can use PnP Powershell in a Powershell script:
# Get credentials from the windows credentials manager
$creds = Get-StoredCredential -Target 'my.company.url'
# Define site and list name
$origin_url = "https://company.sharepoint.com/site/business"
$origin_list = "Listname"
$destination_url = "https://company.sharepoint.com/site/party"
$destination_list = "Listname"
# Connect to the origin site
$o = Connect-PnPOnline –Url $origin_url -Credentials $creds -ReturnConnection
# Connect to the destination site
$d = Connect-PnPOnline –Url $destination_url -Credentials $creds -ReturnConnection
# Get all items in the origin list
$all = Get-PnPListItem -List $origin_list -Connection $o
# Loop over all items in origin
# Get all required information for the associated ID
# Add it to the destination list
Write-Host "--- Copying items ---"
foreach($id in $all) {
$term = $id.FieldValues
$itemValues = @{
"Columnname1" = $term["Columnname1"];
"Columnname2" = $term["Columnname2"];
"Columnname3" = $term["Columnname3"];
"Columnname4" = $term["Columnname4"];
}
Add-PnPListItem -List $destination_list -Values $itemValues -Connection $d
}
# Close connection to sites
Disconnect-PnPOnline -Connection $o
Disconnect-PnPOnline -Connection $d
All works, but the loop that copies list items one-by-one is rather slow (approximately 1 item per second). Is it possible to speed this up or parallelize it somehow?