# Check to ensure Microsoft. sharepoint. powershell is loaded $ snapin = Get-pssnapin | where-object {$ _. name-EQ 'Microsoft. sharepoint. powershell '} if ($ snapin-EQ $ null) {write-host "loading SharePoint powershell snapin" Add-pssnapin "Microsoft. sharepoint. powershell "} $ web = Get-spweb-identity http: // gdcvmg_sps01write-host $ web $ Destination =" C: \ Test2 \ "$ list = $ web. getlist ("document lib Test2") functi On processfolder {param ($ folderurl) $ folder = $ web. getfolder ($ folderurl) foreach ($ file in $ folder. files) {# ensure destination directory $ destinationfolder = $ destination + "/" + $ folder. URL if (! (Test-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 () }# download root filesprocessfolder ($ list. rootfolder. URL) # download files in foldersforeach ($ folder in $ list. folders) {processfolder ($ folder. URL )}