I have Following PowerShell Script which downloads documents from document library with folders to a local drive. it also downloads metadata of each document in CSV file. How do I copy the folder path of each document in same CSV file?
if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null) { Add-PSSnapin Microsoft.SharePoint.PowerShell } $destination = "C:\\FolderName\\" $web = Get-SPWeb -Identity "http://XYZ:2010/" $list = $web.GetList("http://XYZ:2010/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() $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"] } $exportlist += $obj $exportlist | Export-Csv -path 'C:\FolderName\MyList.csv' -noType } #Download root files ProcessFolder($list.RootFolder.Url) #Download files in folders foreach ($folder in $list.Folders) { ProcessFolder($folder.Url) } #DownloadMetadata ($list.RootFolder.Url)