Last active
August 12, 2017 19:48
-
-
Save star-crossed/e5a51698fffebbd0cd65f2fe7d27d291 to your computer and use it in GitHub Desktop.
Recursively get files in 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
$spWeb = get-SPWeb "localhost" | |
function getFiles ([Microsoft.SharePoint.SPFolder]$parentFolder) { | |
$files = $parentFolder.Files | |
foreach($file in $files) { | |
Write-Host $file.Name $file.TimeLastModified | |
$b = $file.OpenBinary() | |
$fs = New-Object System.IO.FileStream(("\\server\exportfiles\"+$file.name), [System.IO.FileMode]::Create) | |
$bw = New-Object System.IO.BinaryWrite($fs) | |
$bw.Write($b) | |
$bw.Close() | |
} | |
$folders = $parentFolder.Folders | |
foreach($childFolder in $folders) { | |
getFiles($childFolder) | |
} | |
return | |
} | |
$rootFolder = $spWeb.GetFolder("Lists/My Doc Sets") | |
getFiles($rootFolder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 15 $folders = $parentFolder.Folders
Should be $folders = $parentFolder.SubFolders
That runs, but now something with my filestream, as it moves filename into export location, but file size is 0kb.
But this helps a ton, thanks Paul!
-TRM