0

I have two lists in SharePoint Online:

1. List1["https://siteName.sharepoint.com/sites/Test1"] (Importing items form excel)
   Fields: Name,Contact,Email
2. List2["https://siteName.sharepoint.com/"]
   Fields: Name,Contact,Email
3. List3["https://siteName.sharepoint.com/sites/Test3"]
   Fields: Name,Contact,Email

List1 and List2 have list-items and List3 has only fields My requirement is that I want to merge List1 and List2 in List3.

For example, In List1 - 10 items and in List2 - 30 items then I need 40 items in List3

How can i achieve this?

Thanks in advance.

1
  • Are they from a different site collections or same site collection (Like Subsite)?
    – Sukumar MS
    Commented Sep 23, 2019 at 11:30

1 Answer 1

1

You can get a list of all of the items and write them to a csv using the script below. Make sure to replace the site name, list name, and fieldvalues.columnName before running.

Connect-PnPOnline "https://tenant.sharepoint.com/site1"
$csv = "path/to.csv"
$List1 = Get-PnPList -Identity "List1Name"
$items = Get-PnPListItem -List $List1
foreach ($item in $items) {
    $item.FieldValues
    $newRow = "{0},{2},{3}" -f $item.FieldValues.name, $item.FieldValues.Contact, $item.FieldValues.Email
    $newRow | Add-Content -path $csv
}

You can repeat the same script for the second list to create a csv with all of the items from lists 1 and 2. Once that is complete, you can then use the below to add all of the items in the csv to list3.

Connect-PnPOnline "https://tenant.sharepoint.com/site2"
$list3 = Get-PnPList -Identity "List3"

foreach ($row in $csv) {
    Add-PnPListItem -List $list3 -Values @{"Name" = $row.name; "Contact" = $row.Contact; "Email" = $row.Email}
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.