1

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? – Nadeem Yousuf Feb 27 '14 at 6:56
  • No. I am still searching for it. Trying to write my own PowerShell but no success so far. You have anything? – SharePointMan Feb 27 '14 at 7:03
2

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
}
$SPWeb.Dispose()

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)
    $bw.Write($b)
    $bw.Close()
}

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. – SharePointMan Feb 27 '14 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. – Nadeem Yousuf Feb 27 '14 at 8:16
  • What do you mean by path? Is it the url to display form of the item? – Nadeem Yousuf Feb 27 '14 at 9:26
  • It should be something like this $url = $SPWeb.Url + "/Lists/Employee/DispForm.aspx?ID=" + "$_Id – Nadeem Yousuf Feb 27 '14 at 9:41
  • can we keep log of each file downloaded with success or not in same CSV file? – SharePointMan Feb 27 '14 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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