Copy SharePoint Online list items from one site to another one
Below you can find a PowerShell script to copy items from one SharePoint list at one site to another SharePoint list in another site. I use it with several modifications to work with the data in test environments.
What you need to execute the script, which?
At first, you need PnP PowerShell installed. How to install it, read at Installing PnP PowerShell | PnP PowerShell and follow all the steps.
The second, you need to have a destination list created. In my example they are similar, but you can also modify the script and insert the data to other fields. That's why I prefer to create SharePoint lists also with PnP PowerShell scripts.
$url = "https://myteenant.sharepoint.com/sites/Customer/Reporting1"
$listTitle = 'RnDSource'
$urlDest = 'myteenant.sharepoint.com/sites/Customer/ReportingDemo'
$listTitleDst = 'RnDDest'
#-ReturnConnection is a very important flag! You will use it below
$srcConn = Connect-PnPOnline -Url $url -Interactive -ReturnConnection
$destConn = Connect-PnPOnline -Url $urlDest -Interactive -ReturnConnection
#this string gets the data from the source list, you can also update it to your task
$srcItems = Get-PnPListItem -List $listTitle -PageSize 1000 -Connection $srcConn
-Query "<View><Query><Where><And>
<Leq><FieldRef Name='ID'/><Value Type='Number'>1400</Value></Leq>
<Geq><FieldRef Name='ID'/><Value Type='Number'>400</Value></Geq>
</And></Where></Query></View>"
$dstList = Get-PnPList -Identity $listTitleDst -Web $urlDest
foreach($item in $srcItems) {
$title = $item['Title']
$compId = $item['Comp_Id']
$date = $item['Date']
$fundtype = $item['Fund_type']
$quarter = $item['CurrentQuarter']
$amount = $item['Amount']
$technologie = $item['Technologie']
Add-PnPListItem -List $listTitleDst -Values @{ "Title" = $title;
"Comp_Id" = $compositeId; "Date" = $date;
"Fund_type" = $fundtype;
"Quarter" = $quarter;
"Amount" = $amount;
"Technologie" = $technologie
} -Connection $destConn
}
For columns fields, you should use Internal field names.