Articles about European Sharepoint Hosting Service
SharePoint 2013 Hosting – HostForLIFE :: How to Copy Item Attachments To SharePoint Library Using PnP PowerShell?
In this blog, we are going to learn how to copy the attachments from a single list item to SharePoint library using PnP PowerShell. The following snippet helps, you to get the attachments from a list item and uploads to the shared Documents library in a current context site.
1 2 3 4 5 6 7 |
$cred = Get-Credential Connect-PnPOnline -Url https://ktskumartenant.sharepoint.com/sites/dev -Credential $cred $listitem = Get-PnPListItem -List Employee -Id 2 $attachments = ForEach-Object{Get-PnPProperty -ClientObject $listitem -Property "AttachmentFiles"} $attachments | ForEach-Object { Copy-PnPFile -SourceUrl $_.ServerRelativeUrl –TargetUrl “Shared Documents/$($_.FileName)” |
After running the powershell command, it asks us to confirm the sourceurl and target url. If the file already exists in the targeturl, we have to add -OverwriteIfAlreadyExists $true to avoid the file already exists error.
Below is the example copies the two attachments from the single list item to the folder within a SharePoint library.
Print article | This entry was posted by Peter on January 7, 2021 at 7:59 am, and is filed under Other Related Post. Follow any responses to this post through RSS 2.0. Both comments and pings are currently closed. |