Download all Documents in a Library View
The PowerShell below will download all documents in a given SharePoint Document Library view to the local folder. This can be safely run on end user Windows PC and does not require SharePoint server access or object model. The design relies solely upon HTTP to discover the list of Document URLs then HTTP to download the binary content. Simple and straight forward.
Just edit the URL and GUID number on the first 3 lines and you’re ready to run. Alternatively, you can supply those values via CMD parameter like this:
.\SPDownloadView.ps1 -url "http://portal/sites/test" -listID "41E5FC8E-D174-4F48-AC3C-79F999A045D1" -viewID "5E9415B3-3C63-48AD-9DC2-A5A282B61790"

Source Code
# Download all files from a SharePoint Document Library view to the local folder over HTTP remotely. # No server side requirement, can run anywhere, including end user desktops. param ( $url, # "http://portal/sites/test", $listID, # "41E5FC8E-D174-4F48-AC3C-79F999A045D1", $viewID # "5E9415B3-3C63-48AD-9DC2-A5A282B61790" ) # Current folder $scriptpath = Split-Path $MyInvocation.MyCommand.Path # Open file list Write-Host "Opening $url" $ows = "$url/_vti_bin/owssvr.dll?Cmd=Display&List={$listID}&View={$viewID}&XMLDATA=TRUE" $owsList = "$url/_vti_bin/owssvr.dll?Cmd=ExportList&List={$listID}&XMLDATA=TRUE" $r = Invoke-WebRequest $ows -UseDefaultCredentials $rList = Invoke-WebRequest $owsList -UseDefaultCredentials $xml = $r.Content $xmlList = $rList.Content $folder = $xmlList.List.Url # Client $client = New-Object System.Net.WebClient $client.UseDefaultCredentials = $true # Loop and download foreach ($row in $xml.xml.data.row) { $name = $row.ows_LinkFilename $from = "$url/$folder/$name" $client.DownloadFile($from, "$scriptpath\$name") } Write-Host "DONE"
Video
References
- http://stackoverflow.com/questions/8343767/how-to-get-the-current-directory-of-the-cmdlet-being-executed
- https://blogs.msdn.microsoft.com/kaevans/2009/05/01/getting-xml-data-from-a-sharepoint-list-the-easy-way/
- http://stackoverflow.com/questions/18866958/downloading-a-file-from-sharepoint-online-with-powershell