On 29/04/2024
SharePoint Copy ListItem / Duplicate ListItem
[string]$url = "https://yourSite.sharepoint.com/sites/test";
[string]$listTitle = "AddHistoryInExcel";
[int]$itemId = 17;
[string]$fieldsToCopy = "Title,WFInstance,ItemId,TargetListId,TargetDocLibPath";
Connect-PnPOnline -Url $url -Interactive
$itemToCopy = Get-PnPListItem -List $listTitle -Id $itemId
$list = Get-PnPList -Identity $listTitle
$ListItemInfo = New-Object Microsoft.SharePoint.Client.ListItemCreationInformation
$ListItem = $list.AddItem($ListItemInfo)
foreach($field in $fieldsToCopy.Split(","))
{
$ListItem[$field] = $itemToCopy[$field]
}
$ListItem.Update()
Invoke-PnPQuery
Write-Host "ItemId $($itemId) has been duplicated target id $($ListItem.Id) "