Requirement: Copy List items to another list in SharePoint Online
How to copy list items to another list in SharePoint Online?
Use Quick Edit (Datasheet view) to copy-paste list items between lists in SharePoint online. Make sure you have matching columns and column order is same in both views.
SharePoint Online: Copy List Item to Another List using PowerShell
SharePoint Online: Copy List items using PowerShell
Here is my another post for SharePoint On-premises to copy list item: Copy SharePoint List Item to Another List using PowerShell
How to copy list items to another list in SharePoint Online?
Use Quick Edit (Datasheet view) to copy-paste list items between lists in SharePoint online. Make sure you have matching columns and column order is same in both views.
SharePoint Online: Copy List Item to Another List using PowerShell
#Load SharePoint CSOM AssembliesThis script copies all mapped column values from the source to the target list. Lets enhance the script bit to automatically copy all columns matching from the source to target list.
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Function Copy-ListItems()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $SourceListName,
[Parameter(Mandatory=$true)] [string] $TargetListName
)
Try {
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#Get the Source List and Target Lists
$SourceList = $Ctx.Web.Lists.GetByTitle($SourceListName)
$TargetList = $Ctx.Web.Lists.GetByTitle($TargetListName)
#Get All Items from Source List
$SourceListItems = $SourceList.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$Ctx.Load($SourceListItems)
$Ctx.ExecuteQuery()
#Get each column value from source list and add them to target
ForEach($SourceItem in $SourceListItems)
{
$NewItem =New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$ListItem = $TargetList.AddItem($NewItem)
#Map each field from source list to target list - INTERNAL NAMES
$ListItem["Title"] = $SourceItem["Title"]
$ListItem["IsActive"] = $SourceItem["IsActive"]
$ListItem["ProjectStartDate"] = $SourceItem["ProjectStartDate"]
$ListItem["Department"] = $SourceItem["Department"]
$ListItem["Priority"] = $SourceItem["Priority"]
$ListItem.update()
}
$Ctx.ExecuteQuery()
write-host -f Green "Total List Items Copied from '$SourceListName' to '$TargetListName' : $($SourceListItems.count)"
}
Catch {
write-host -f Red "Error Copying List Items!" $_.Exception.Message
}
}
#Set Parameters
$SiteURL= "https://crescent.sharepoint.com/"
$SourceListName="Projects Template"
$TargetListName="Project Innovate"
#Call the function to copy list items
Copy-ListItems -siteURL $SiteURL -SourceListName $SourceListName -TargetListName $TargetListName
SharePoint Online: Copy List items using PowerShell
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Function Copy-ListItems()
{
param
(
[Parameter(Mandatory=$true)] [string] $SiteURL,
[Parameter(Mandatory=$true)] [string] $SourceListName,
[Parameter(Mandatory=$true)] [string] $TargetListName
)
Try {
#Setup Credentials to connect
$Cred = Get-Credential
$Cred = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Cred
#Get the Source List and Target Lists
$SourceList = $Ctx.Web.Lists.GetByTitle($SourceListName)
$TargetList = $Ctx.Web.Lists.GetByTitle($TargetListName)
#Get All Items from Source List
$SourceListItems = $SourceList.GetItems([Microsoft.SharePoint.Client.CamlQuery]::CreateAllItemsQuery())
$Ctx.Load($SourceListItems)
$Ctx.ExecuteQuery()
#Get All fields from Source List & Target List
$SourceListFields = $SourceList.Fields
$Ctx.Load($SourceListFields)
$TargetListFields = $TargetList.Fields
$Ctx.Load($TargetListFields)
$Ctx.ExecuteQuery()
#Get each column value from source list and add them to target
ForEach($SourceItem in $SourceListItems)
{
$NewItem =New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$ListItem = $TargetList.AddItem($NewItem)
#Map each field from source list to target list
Foreach($SourceField in $SourceListFields)
{
#Skip Read only, hidden fields, content type and attachments
If((-Not ($SourceField.ReadOnlyField)) -and (-Not ($SourceField.Hidden)) -and ($SourceField.InternalName -ne "ContentType") -and ($SourceField.InternalName -ne "Attachments") )
{
$TargetField = $TargetListFields | where { $_.Internalname -eq $SourceField.Internalname}
if($TargetField -ne $null)
{
#Copy column value from source to target
$ListItem[$TargetField.InternalName] = $SourceItem[$SourceField.InternalName]
}
}
}
$ListItem.update()
$Ctx.ExecuteQuery()
}
write-host -f Green "Total List Items Copied from '$SourceListName' to '$TargetListName' : $($SourceListItems.count)"
}
Catch {
write-host -f Red "Error Copying List Items!" $_.Exception.Message
}
}
#Set Parameters
$SiteURL= "https://crescent.sharepoint.com/"
$SourceListName="Projects Template"
$TargetListName="Project Innovate"
#Call the function to copy list items
Copy-ListItems -siteURL $SiteURL -SourceListName $SourceListName -TargetListName $TargetListName
Here is my another post for SharePoint On-premises to copy list item: Copy SharePoint List Item to Another List using PowerShell