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.

0.0.png

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

0.1.png

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

1.png

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

2

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

3

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

4.png

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

5.png

Hope you find it helpful.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s