How to: Perform Bulk Downloads of Files in SharePoint


This post is going to discuss how to perform a bulk file copy from a SharePoint library to a folder on the file system. Along with this blog post, I will also provide a downloadable script, which can be modified to work in your environment. As we are copying files from SharePoint to the file system, all metadata will be stripped. Additional work could be performed in order to export the metadata to an xml file. This functionality is currently not available in the version of the script provided.




I was recently working with a customer who needed to export files from one SharePoint environment and import them into another SharePoint environment. Though SharePoint does have this functionality built-in using Export-SPWeb and Import-SPWeb, in this case an export resulted in no files being exported from the desired directory. This was later determined to be corruption of the files after the export was unsuccessful on the desired directories.




In this case, the approach was simple enough. Read the folder and file structure from the specified list and replicate that structure on the file system.




This solution is tricky enough because of the way files are accessed in SharePoint lists. Enumerating all files in the list can be performed, however folder structure would not be maintained by calling $List.Items. In this case, what we have to do is perform two separate actions. One action to retrieve the root folder of the list and enumerate the items, and one action to enumerate each folder and each file in each folder. In order to do this, we call $List.rootfolder.files

We also need to enumerate all folder, and enumerate all of the files in each folder. This can be done by using $List.folders. This will list all folders (including subfolders) for the list.

$Folder.folder.files allows you to enumerate all files in a specific folder


Now that we have a collection of all of the files and their directories, we can export the files to the file system. This can be performed by accessing the binary steam of the SharePoint file, and assigning it to the binary stream of a file system object. This is performed by using the following snippet of code.


Once the script has been exported, the structure of the files and folders will be maintained on the file system as they were in the SharePoint site.


Download the Script


The script can be downloaded from the following location:
BulkFileExport.ps1 (compressed)




This script does require some edits. All edits are explained at the top of the script. Each child directory must be specified in the script. Each library which is to be exported will need to be added to the script using the three lines of PowerShell which are included. Here is a brief explanation.

This next line will create a directory at the specified location. In this example, a directory will be made beneath the root directory and will be named StyleLibrary
New-Item -Path ($Directory + “\StyleLibrary”) -ItemType Directory


This next line will retrieve a list with the specified title, and assign it to a variable. The variable name is not important, as long as the correct variable is passed to the ExportFiles Function in the next line
$StyleLibrary = $Site.RootWeb.Lists | ? {$_.title -eq “Style Library”}


This next line will export files from the list specified via the first variable and to the subdirectory specified in the second variable.
ExportFiles $StyleLibrary “StyleLibrary”




As always, feedback and suggestions are always welcome. If you do have any ideas on how to improve the script, I’d love to hear them.

You can also follow me on Twitter:


Comments (4)

  1. Lukas_UK says:

    Hi Roger,

    Two questions:

    1. How do you add the filter to copy/move just the files that you want (not all of them), eg. where content type equals "Something" and fieldname equals "Something else"? I want to filter for those files but still preserve original folder structure as you do in your script.

    2. When we move the files from SharePoint into the file server and crawl that file server with SharePoint for the Search Centre, do those files on file server retain their original metadata once created in sharepoint (MS Office files) ?

  2. Trevor_US says:

    This doesnt seem to work for me. It works on the example provided for the styles library but when I try to get a library from a subsite it says that I cant start with a null reference. I think its because the folder has subfolders but not sure. Whatever the reason I have tried everything I can think and it just doesnt work.

  3. Tom.Brown says:

    Great article, thanks for your information, I used this SharePoint auditing tool( that allows to export all sites, list, content,group, files and folder and track all events in some particular site collections including sensitive data and to collect data from multiple SharePoint Servers and view data of who is doing what and where in your SharePoint environment.

  4. Vasily Ingogly says:

    Hi Roger,

    I’m trying to modify the script to export libraries from a subsite rather than a site collection — so I replaced the Get-SPSite call with a Get-SPWeb call. The script runs without errors, and creates the directory at the specified location, but the ExportFiles function isn’t exporting anything. Am I missing some other change that’s needed to the script for it to work on a subsite?

Skip to main content