With The help of this forum I am able to Write The following Script Using powershell which downloads bulk data from SharePoint with Metadata in CSV file and also Error log as txt file. but the problem I am facing here is, it only Copies last error.i want copy of all errors in Txt file.
I tried using
Set-Content "c:\" $error
still not able to solve it.
if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}
try
{
$destination = "C:\\Test\\"
$web = Get-SPWeb -Identity "http://xyz:4444/"
$list = $web.GetList("http://xyz:4444/Shared Documents/")
function ProcessFolder {
param($folderUrl)
$folder = $web.GetFolder($folderUrl)
foreach ($file in $folder.Files) {
#Ensure destination directory
$destinationfolder = $destination + "/" + $folder.Url
if (!(Test-Path -path $destinationfolder))
{
$dest = New-Item $destinationfolder -type directory
}
#Download file
$binary = $file.OpenBinary()
d
e
$stream = New-Object System.IO.FileStream($destinationfolder + "/" + $file.Name), Create
$writer = New-Object System.IO.BinaryWriter($stream)
$writer.write($binary)
$writer.Close()
}
}
$exportlist = @()
$list.Items | foreach {
$obj = New-Object PSObject -Property @{
"Title" = $_["Title"]
"Name" = $_["Name"]
"Modified Date" = $_["Modified"]
"Modified By" =$_["Modified By"]
"Size"= $_["File Size"]
"Path" = $web.Url + "/" + $_.File.Url
}
$exportlist += $obj
$exportlist | Export-Csv -path 'C:\Test\MyList.csv' -noType
}
#Download root files
ProcessFolder($list.RootFolder.Url)
#Download files in folders
foreach ($folder in $list.Folders) {
ProcessFolder($folder.Url)
}
}
catch
{
#Write "Error: copy-item: $_" >>c:\logfile.txt
$("$file.name: " + $_.Exception.Message) | out-file c:\file.log -Append
#set-content "c:\log2.txt" $error
}
finally
{
#Download root files
ProcessFolder($list.RootFolder.Url)
#Download files in folders
foreach ($folder in $list.Folders) {
ProcessFolder($folder.Url)
}
}
#DownloadMetadata ($list.RootFolder.Url)