Get All Documents From A SharePoint Document Library To A Local Folder Using PowerShell

Welcome to an article on how to get all documents from a SharePoint Document Library to a local folder using PowerShell Script.

Sometimes we need all our files in a document library for a requirement and if there are many you can’t download one by one or use ‘Open with explorer option’ if your company policy does not allows you to use this function.

You have a choice, using this script which will take hardly any time to download all your documents at once to your local folder.

How? Let’s see it.

  1. Open Windows PowerShell Modules as an Administrator.


    1. Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue  
    2. #Call the Web Service here  
    3. $SPWeb = Get-SPWeb "Provide your web here"  
    4. #Open the library here  
    5. $docfiles = $SPWeb.GetFolder("Provide your Document Library name here").Files  
    6. foreach ($docfile in $docfiles) {  
    7. #Download each file here  
    8. Write-host "Download Completed for" $docfile.Name   
    9. $bin = $docfile.OpenBinary()  
    10. $opendoc = New-Object System.IO.FileStream(("Provide your Local Location here"+$docfile.Name), [System.IO.FileMode]::Create)  
    11. $docgen = New-Object System.IO.BinaryWriter($opendoc)  
    12. $docgen.Write($bin)  
    13. $docgen.Close()  
    14. }  
  2. Save the above code in a notepad as .ps1 file.

  3. Run the code on the Windows PowerShell Modules.

  4. It will display the file name it is downloading and all the files will start getting downloaded to your local.

It will be so quick that you won’t take much time and effort on this, thereby saving a lot of time and effort. Run the script and you have all the files on your local server.