SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following script to download documents from document library. Is there any way I can download folders starting with A to J from root level which should include all of their sub folders from A to Z. Only from top level it should download A to j

if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)
        Add-PSSnapin Microsoft.SharePoint.PowerShell

    $destination = "C:\\Test\\"
    $web = Get-SPWeb -Identity "http://xyz:4444/"
    $list = $web.GetList("http://xyx:4444/Shared Documents/")

    function ProcessFolder {
        $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)
            #Add-content "c:\log3.txt"  $error
            Write "Error: $ $_" >>c:\logfile.txt


    $exportlist = @()
    $list.Items | foreach {
    $obj = New-Object PSObject -Property @{
    "Title" = $_["Title"]
    "Name" = $_["Name"]
    "Modified Date" = $_["Modified"]
    "Modified By" =$_["Modified By"]
    "Size"= $_["File Size"]
    "Path" = $web.Url + "/" + $_.File.Url

    $exportlist += $obj
    $exportlist | Export-Csv -path 'C:\Test\MyList.csv' -noType

    #Download root files
    #Download files in folders
    foreach ($folder in $list.Folders) {

share|improve this question
so what is exactly your problem? Is it the downloading of the structure of filtering it to A-J ? – luccio Jun 25 '14 at 10:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.