Created
October 13, 2016 22:30
-
-
Save cloaked-ninja/9ff2991353238270446af208f039aa52 to your computer and use it in GitHub Desktop.
download files from sharepoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$destination = "C:\users\userName\desktop\testFolder" | |
$webUrl = "http://sharetest" | |
$listUrl = "http://sharetest/office" | |
############################################################## | |
$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 + "/" + $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() | |
} | |
} | |
#Download root files | |
ProcessFolder($list.RootFolder.Url) | |
#Download files in folders | |
foreach ($folder in $list.Folders) { | |
ProcessFolder($folder.Url) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment