Question

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.

Was it helpful?

Solution

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/

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top