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?

Downloading all files from SharePoint can be a daunting task, especially when you have a large number of files and folders. However, it is a necessary task when you need to back up data or move it to another platform. 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 the library. Fortunately, there is an easy way to do this! Let’s explore how to download all the document libraries of a site easily:

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

  1. Navigate to your SharePoint On-premises or SharePoint Online library.
  2. Click on “View in File Explorer” from the Views Drop down in SharePoint Online. For SharePoint On-premises, click on the “Open with Explorer” button in the “Library” tab.
  3. 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
  4. 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

Quite simple, huh! However, It can be a daunting task to download all documents from all libraries in SharePoint Online manually. As a solution, PowerShell is an efficient way to automate this process. Let’s see how to download all documents from all document libraries in SharePoint Online using PowerShell.

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, and document versions, list item attachments of the given site, and its subsites to the local disk path provided. You may have to log in to the SharePoint server site once to establish a session cookie, BTW!

#Configuration Parameters
$DownloadPath= "c:\Downloads\Online"
#$WebDavUrl = "\\\DavWWWRoot\sites\operations"
$webDavUrl = "\\\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

If you need to download all documents from SharePoint Online for backup, migration or archiving purposes, it can be a tedious task to do it manually. Here is the PowerShell script to automate it:

#Function to download a library from SharePoint Online
Function Download-PnPLibrary
    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

$SiteURL = ""
$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

This article discussed downloading all documents from SharePoint Online with different methods available. Depending on your specific needs, you can quickly and easily download all documents from a specific library to your local machine.

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

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

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

  • Hi Salaudeen,
    Thanks for the script!
    The script runs great for a while and then I get this error:
    Error downloading Library “Documents” : A task was cancelled.

  • I keep getting throttled and then the download stops after 100 seconds. Anyway to stop that?

  • How can I do this on a Mac?

  • HI,

    I getting below error,
    Download-PnPLibrary : Cannot process argument transformation on parameter ‘List’. Cannot convert the
    “Microsoft.SharePoint.Client.List” value of type “Microsoft.SharePoint.Client.List” to type “Microsoft.SharePoint.Client.List”.
    At line:79 char:31

    Thanks in advance

    • Hi,
      I need to download all files from all the libraries form SharePoint only including all its subsites.
      I cannot use WebDav though.
      Which script is most suitable?

  • I am using get-pnpfile to extract files from SPO and working around the local issue of long paths but hitting a problem that seems to not have an answer in that when the request url is over 260 chars it fails with the maxurl error. I have searched high and low for an answer. Anyone have anything that may be reading this?

  • Hi Salaudeen,

    You didn’t know how you save me by using your first script on top. I am new to SPO and PowerShell and search all over the internet to get a simple script to download a specific folder(s) to my SPO.

    Again, thank you so much.

  • How do you address :Error Downloading Library ‘Documents’ : The length of the URL for this request exceeds the configured maxUrlLength value.” error

    • By default, the IIS is set to handle up to 260 character long URLs. You can increase this limit in the web.config file:

      <httpRuntime maxUrlLength="500" />

    • I am trying to get it working on Office 365. I didn’t think it was possible to edit web.config file on SharePoint online?

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



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


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


Leave a Reply

Your email address will not be published. Required fields are marked *