1

I have 10,000 documents in SharePoint 2010 library. Is there any PowerShell script which will download all documents from SharePoint document library but I won't need the folder structure to be downloaded, all the documents from the sub-folders also should be downloaded to one physical location and rename all documents with some 'prefix' while downloading to physical location.

2

I have modified the script from this URL to adjust with your requirements

######################## Start Variables ########################
######################## Varun's Script######################
$destination = "C:\\tools\\Folder"
$webUrl = "<Url of the specific site>"
$listUrl = "<Url of the specific list. This url is complete Url and NOT relative url>"
##############################################################

$web = Get-SPWeb -Identity $webUrl
$list = $web.GetList($listUrl)

function ProcessFolder {
    param($folderUrl)
    $folder = $web.GetFolder($folderUrl)
    foreach ($file in $folder.Files) {
        #Ensure destination directory
        $destinationfolder = $destination

        #Download file
        $binary = $file.OpenBinary()
        $stream = New-Object System.IO.FileStream($destinationfolder + "\PREFIX_" + $file.Name), Create
        $writer = New-Object System.IO.BinaryWriter($stream)
        $writer.write($binary)
        $writer.Close()
    }
}

#Download root files
ProcessFolder($list.RootFolder.Url)
#Download files in folders
foreach ($folder in $list.Folders) {
    ProcessFolder($folder.Url)
}
  • Thanks , but the above script will download with entire folder structure but is there any way by which I can flatten folders also. – abc Jul 15 '16 at 15:55
  • I have made the script to flatten the files.. have you tried the above script i have posted? – Amal Hashim Jul 15 '16 at 15:56
  • Yes , I have tried but the output is like below. – abc Jul 15 '16 at 16:11
  • Folder1 ->file1 ->Folder2 ->file2 but i need as Folder1->file1->file2 – abc Jul 15 '16 at 16:13
  • It's giving error for this line any solution? $stream = New-Object System.IO.FileStream($destinationfolder + "\PREFIX_" + $file.Name), Create – abc Jul 16 '16 at 5:47

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.