How to Download All Files from a SharePoint Site?

Requirement: Download All Files from a SharePoint Site.

How to Download All Files in SharePoint Site?

When you have lots of different document libraries with files in them, it takes quite a bit of time to download all the files from one library. Fortunately, there is an easy way to do this! Let’s explore how to easily download all the documents libraries of a site.

To download all files from a SharePoint document library or folder, Simply use the “Explorer View”.

  • Navigate to your SharePoint On-premises or SharePoint Online library.
  • Click on “View in File Explorer” from Views Drop down in SharePoint Online. For SharePoint On-premises, click on “Open with Explorer” button in “Library” tab.
  • From the Explore view, you can download all documents or all attachments from any list or library to your local machine.
    sharepoint download all documents in a library
  • Now in the Explorer view, navigate one level up, and you can download the complete site or site collection using explorer view by navigating up and down to the site, list or library objects.
    download all files from sharepoint
In modern libraries, You can simply select all files and hit “Download” button to download all files from a document library.

PowerShell to Download All Files from SharePoint On-Premises/Online site:

We can also use the WebDav method to download all files from a SharePoint site or site collection. Just set the parameters in the below script and hit run. This PowerShell script copies all files, including files in all libraries, document versions, list item attachments of the given site and its subsites to the local disk path provided. You may have to login to the SharePoint site once to establish a session cookie, BTW!

#Configuration Parameters
$DownloadPath= "c:\Downloads\Online"
#$WebDavUrl = "\\intranet.crescent.com\DavWWWRoot\sites\operations"
$webDavUrl = "\\[email protected]\DavWWWRoot\sites\operations" #SharePoint Online

#Create Local Folder it it doesn't exists
If(!(Test-Path $DownloadPath))
{
      New-Item -ItemType Directory -Force -Path $DownloadPath | Out-Null
}

#Get All files from the Site and download to local folder
Get-ChildItem -Path $webDavUrl -Recurse | ForEach-Object {
    #Frame the destination path
    $DestinationPath = Join-Path -Path $DownloadPath -ChildPath (Split-Path $_.FullName -NoQualifier).Replace($webDavUrl,'');

    #Copy File to local path
    Copy-Item $_.FullName -Destination $DestinationPath -Force

    Write-host -f Green File Copied to $DestinationPath
}

This method works in both SharePoint on-premises and SharePoint Online.

PnP PowerShell to Download All Document Libraries from a SharePoint Online Site

#Function to download a library from SharePoint Online
Function Download-PnPLibrary
{
    [cmdletbinding()]
    param
    (
        [Parameter(Mandatory=$true)][Microsoft.SharePoint.Client.List]$List,
        [Parameter(Mandatory=$true)][string]$DownloadPath
    )
    Try {
        Write-host -f Yellow "Downloading Document Library:"$List.Title
        #Create a Local Folder for the Document Library, if it doesn't exist
        $LibraryFolder = $DownloadPath +"\" +$List.RootFolder.Name
        If (!(Test-Path -Path $LibraryFolder)) {
                New-Item -ItemType Directory -Path $LibraryFolder | Out-Null
        }

        #Get all Items from the Library - with progress bar
        $global:counter = 0
        $ListItems = Get-PnPListItem -List $List -PageSize 500 -Fields ID -ScriptBlock { Param($items) $global:counter += $items.Count; Write-Progress -PercentComplete `
                    ($global:Counter / ($List.ItemCount) * 100) -Activity "Getting Items from Library:" -Status "Processing Items $global:Counter to $($List.ItemCount)";} 
        Write-Progress -Activity "Completed Retrieving Items from Library $($List.Title)" -Completed

        #Get all Subfolders of the library
        $SubFolders = $ListItems | Where {$_.FileSystemObjectType -eq "Folder" -and $_.FieldValues.FileLeafRef -ne "Forms"}
        $SubFolders | ForEach-Object {
            #Ensure All Folders in the Local Path
            $LocalFolderPath = $DownloadPath + ($_.FieldValues.FileRef.Substring($Web.ServerRelativeUrl.Length)) -replace "/","\"
            #Create Local Folder, if it doesn't exist
            If (!(Test-Path -Path $LocalFolderPath)) {
                    New-Item -ItemType Directory -Path $LocalFolderPath | Out-Null
            }
            Write-host -f Green "`tEnsured Folder '$LocalFolderPath'"
        }

        #Get all Files from the folder
        $FilesColl =  $ListItems | Where {$_.FileSystemObjectType -eq "File"}

        #Iterate through each file and download
        $FilesColl | ForEach-Object {
            #Frame the Parameters to download file
            $FileDownloadPath = ($DownloadPath + ($_.FieldValues.FileRef.Substring($Web.ServerRelativeUrl.Length)) -replace "/","\").Replace($_.FieldValues.FileLeafRef,'')
            $FileName = $_.FieldValues.FileLeafRef
            $SourceURL = $_.FieldValues.FileRef
            #Download the File
            Get-PnPFile -ServerRelativeUrl $SourceURL -Path $FileDownloadPath -FileName $FileName -AsFile -force
            Write-host -f Green "`tDownloaded File '$FileName' from '$SourceURL'"
        }
    }
    Catch {
        Write-Host -f Red "Error Downloading Library '$($List.Title)' :"$_.Exception.Message
    }
}

#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$DownloadPath ="C:\Temp\NewDocs"

#Connect to SharePoint Online
Connect-PnPOnline $SiteURL -Interactive
$Web = Get-PnPWeb

#Exclude certain libraries
$ExcludedLists = @("Form Templates", "Preservation Hold Library","Site Assets", "Pages", "Site Pages", "Images",
                            "Site Collection Documents", "Site Collection Images","Style Library")

#Get all non-hidden document libraries 
$DocumentLibraries = Get-PnPList -Includes RootFolder | Where {$_.BaseType -eq "DocumentLibrary" -and $_.Title -notin $ExcludedLists -and $_.Hidden -eq $False}
       
#Enumerate each library
ForEach($Library in $DocumentLibraries)
{
    Download-PnPLibrary -List $Library -DownloadPath $DownloadPath
}

Refer to my other post to download all documents from a library using PowerShell: PowerShell to Download All Files from SharePoint Library

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

2 thoughts on “How to Download All Files from a SharePoint Site?

  • CAn you help me understand why the webDavURL looks funny… ?

    \\[email protected]\DavWWWRoot\sites\operations

    vs.

    crescent.sharepoint.com\sites\operations..

    What’s with the “\\” at the beginning, the “@ssl”, and the “\DavWWWRoot\”

    thanks!

    Reply
    • Well, the WebDav protocol uses this format to access SharePoint: \\[email protected]\DavWWWRoot\sites\YourSite\ . You can open any document library in “File Explore View” to obtain this path quickly.

      Reply

Leave a Reply