In this blog, you'll learn how to use the PnP PowerShell to download the attachments from the specified list item.
Check this
link for downloading multiple files from the given URL using the same PnP PowerShell.
Step 1
First, we have to get the list item from SharePoint.
- $listitem = Get-PnPListItem -List <ListName> -Id <Item ID>
Step 2
Get the attachment for the list item.
- $attachments = ForEach-Object{Get-PnPProperty -ClientObject $listitem -Property "AttachmentFiles"}
Step 3
Download the retrieved attachments from the following path.
- $attachments | ForEach-Object { Get-PnPFile -Url $_.ServerRelativeUrl -FileName $_.FileName -Path "E:\Downloads\" -AsFile }
The below code will authenticate against SharePoint and retrive the list item from Employee list based on the ID 2. And then, it retrieves the collection of attachments and downloads those attachments to the local path "E:\ktskumar\Documents".
- $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 { Get-PnPFile -Url $_.ServerRelativeUrl -FileName $_.FileName -Path "E:\ktskumar\Documents" -AsFile }