Share via


SharePoint 2016/2013/Online: How Download SharePoint List Item Attachments By Powershell Automation

Downloading List Item Attachments is normally required when we are dealing with migration scenarios and sometimes for Custom Backups.

In this article, we will explore the PowerShell to download the List Item attachments.

In order to set up this demo we have created a list and added one List Item with some of the attachments as shown below:

https://howtodowithsharepoint.files.wordpress.com/2016/10/13.png?w=800

Also, we have one folder on the local machine as shown below:

https://howtodowithsharepoint.files.wordpress.com/2016/10/21.png?w=800

In the upcoming section, we will do the Step by Step Code Analysis to get a better understanding of the core functionality.

Step 1: In this step, we will initialize the SharePoint Client Context by passing required credentials.

https://howtodowithsharepoint.files.wordpress.com/2016/10/31.png?w=800

Step 2: In this step, we will initialize the SharePoint List Object by referencing it using current Client Context and setting up the disk location where the attachments will get downloaded.

Step 3: In this step, we will first check the status of any pending request in the queue, and if there is any pending query then first execute it.

Step 4: In this step, we will read the file from SharePoint List Item Attachments collection and save it to the disk location as specified in Step 2.

https://howtodowithsharepoint.files.wordpress.com/2016/10/41.png?w=800

Step 5: In this step, finally we call the “DownloadListItemAttachments” Function that will execute the logic we have seen in above steps.

https://howtodowithsharepoint.files.wordpress.com/2016/10/51.png?w=800

Once you execute the PowerShell it will ask you for the credentials as per the SharePoint Hosting Environment (On-Premises or Online).

Provide the required credentials:

https://howtodowithsharepoint.files.wordpress.com/2016/10/61.png?w=800

If the PowerShell scripts execute successfully it will download all the attachment in the disk location as shown below:

https://howtodowithsharepoint.files.wordpress.com/2016/10/71.png?w=800

https://howtodowithsharepoint.files.wordpress.com/2016/10/81.png?w=800

During the real production scenarios, it is always advisable to keep all attachments of a specific item in a separate folder govern by a proper naming convention to support smooth tracking of the content later on.

That is all for this demo.

Hope you find it helpful.


Back to Top