SharePoint 2016/2013/Online: How to Download SharePoint Files by PowerShell Automation

In this article we will explore the PowerShell way of downloading the files in SharePoint Document Libraries.

By adding some flavor of automation mechanism this technique could be very useful to the scenarios where we need to download documents in bulk in a schedule based job.

In order to setup this demo I have created a document library in my SharePoint Online Site, though this equally applicable to On Premise implementations of SharePoint.

I have added a new document library in SharePoint Online Site by the name “Prashant Documents” with a set of documents uploaded to it.


I have also set up a local folder on the disk drive which will act as destination folder for the files to be downloaded


Step 1: Initiate the Client Context

In order to get more information on Setting up Client Context & other Environmental Configurations, you may visit one of the earlier articles SharePoint Online: How to Install SharePoint Online Management Shell


Step 2: Instantiate & Load SharePoint Document Library Object

Step 3: Load the Root Folder in SharePoint Document Library which is containing the set of documents to be downloaded

Step 4: Using “OpenBinaryDirect” Method that is available in “Microsoft.SharePoint.Client.File” Class to read the file from SharePoint Document Library and save the File Stream to the disk location by using “CopyTo” method which is available in “System.IO.File” Class


Step 5: Call “DownloadFilesFromFolder” function that will download the files to the disk location


Step 6: On execution of this function Windows PowerShell Credential Prompt will appear where we have to specify the password to the login account


Step 7: Once the script executed successfully we can see the documents downloaded into the disk location


Hope you find it helpful.