4

In this script, i want to to copy an item from list to another list. This item contain an attachments. How i can add the attachments to my code

$web = Get-SPWeb http://intranet/sales/
$listSales = $web.Lists["Sales Projects"]


$Prospect = Get-SPWeb http://intranet/CAC/
$listProspect = $Prospect.Lists["Clients"]


foreach ($item in $listSales.Items | Where {$_["Status"] -eq "Confirmed" -and $_["isDone"] -eq $null}) { 

    Write-Host $item.Title

      $newItem = $listProspect.Items.Add();


      $newItem["Client's Name"] = $item["Client Name"]
      $newItem["Initiator"] = $item["Initiator"]


      $newItem.Update()


      $item["isDone"]="Done"
      $item.Update()
}

3 Answers 3

3

You can do it with following code:

foreach ($AttachName in $item.Attachments) 
{
    $spFile = $item.ParentList.ParentWeb.GetFile($item.Attachments.UrlPrefix + $AttachName);
    $newItem.Attachments.Add($AttachName, $spFile.OpenBinary());
}

Put that code after this line: $newItem["Initiator"] = $item["Initiator"] and it should be fine.

0
0

Take a look at this article here:

http://www.sharepointdiary.com/2017/02/sharepoint-online-copy-attachments-from-one-list-to-another-using-powershell.html

0

I may recommend you to try use SharePoint Migration tool from Microsoft for this migrations it's free.

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.