Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.
Microsoft cloud engineer - SharePoint, Office 365, Azure, DotNet, Angular, JavaScript.

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"

Enjoy!

shades_smile

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

© Copyright 2016
@ SPJeff

Return to Top ▲Return to Top ▲