Skip to content

Instantly share code, notes, and snippets.

@star-crossed
Last active August 12, 2017 19:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save star-crossed/e5a51698fffebbd0cd65f2fe7d27d291 to your computer and use it in GitHub Desktop.
Save star-crossed/e5a51698fffebbd0cd65f2fe7d27d291 to your computer and use it in GitHub Desktop.
Recursively get files in SharePoint
$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)
@techrevmarrell
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment