I want to download all the documents from Document Library to a local drive. also I want their security info such as "Modified"", "Modified By" to be included in a CSV file.

I searched around net but couldn't get any useful PowerShell scripts.

if anyone is having such PowerShell script of C# code can share.

  • Have you got any code so far? Commented Feb 27, 2014 at 6:56
  • No. I am still searching for it. Trying to write my own PowerShell but no success so far. You have anything? Commented Feb 27, 2014 at 7:03

1 Answer 1


Here is the code to iterate through the list and get information of the items in the CSV file using PowerShell:

$SPWeb = Get-SPWeb "http://aissp2013:111"
$SPList = $SPWeb.Lists["Employee"]
$exportlist = @()
$SPList.Items | foreach {
$obj = New-Object PSObject -Property @{
"Title" = $_["Title"]
"Name" = $_["Name"]
"Modified Date" = $_["Modified"]
$exportlist += $obj
$exportlist | Export-Csv -path 'C:\MyList.csv' -noType

Source: http://shaiknb.wordpress.com/2013/05/27/powershell-sharepoint-export-list-items-via-view-to-csv/

The code for downloading documents from Document library is:

$SPWeb = Get-SPWeb "http://aissp2013:111"
$files = $SPWeb.GetFolder("Shared Documents").Files
foreach ($file in $files) {
    Write-host $file.Name
    $b = $file.OpenBinary()
    $fs = New-Object System.IO.FileStream(("C:\temp\"+$file.Name), [System.IO.FileMode]::Create)
    $bw = New-Object System.IO.BinaryWriter($fs)

Make sure to create the folder C:\temp first.

Source: http://www.spjeff.com/2013/07/03/powershell-download-all-files-in-a-document-library/

  • Thanks Nadeem.one more issue.how can we have folder structure name in CSV file. Commented Feb 27, 2014 at 7:33
  • The Items property returns all the files in a document library, including files in subfolders, but not the folders themselves. In a document library, folders are not considered items. You may have to use something like foreach (SPListItem item in list.Folders) to get folder info. Commented Feb 27, 2014 at 8:16
  • What do you mean by path? Is it the url to display form of the item? Commented Feb 27, 2014 at 9:26
  • It should be something like this $url = $SPWeb.Url + "/Lists/Employee/DispForm.aspx?ID=" + "$_Id Commented Feb 27, 2014 at 9:41
  • can we keep log of each file downloaded with success or not in same CSV file? Commented Feb 27, 2014 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.