How to Download All Files from OneDrive for Business?

Requirement: Download all files and folders from OneDrive for Business site to the local disk.

How to download all the files from OneDrive?

OneDrive is a cloud-based storage solution from Microsoft that lets you store files online and share them with others. You can access your OneDrive files from any device, and there are several ways to download all the files from your account (or anyone else’s account when you have access!). In this article, we’ll show you how to quickly download OneDrive for Business files through the web browser interface. We’ll also show you how to use PowerShell to download all of your OneDrive for Business files. So let’s get started!

Here are the options available to download OneDrive for Business site:

  1. Select all files and folders and hit Download button in the toolbar
  2. Use the sync option and select “Always Keep on this device”
  3. Use the PowerShell script to download all files and Folders from OneDrive

Option 1: Download All Files and Folders from OneDrive for Business using Web Browser

Microsoft’s OneDrive for Business is a great way to store and share files. But what if you need to download all of the files from your OneDrive for Business account? Well, let me show you how to download all the files from your OneDrive for Business account.

Here is how to download all files from OneDrive for Business in just a few clicks:

  1. Login to your OneDrive site. URL shortcut: https://YourDomain-My.sharepoint.com/ (or any other user’s OneDrive site – provided you have access to their OneDrive site already! If not, use How to Get Access to OneDrive for Business site of Other users?)
  2. Select all files and folders and hit “Download” button from the toolbar.powershell download onedrive for business files

This will download everything from the OneDrive site to a Zip file on your local PC.

Option 2: Download all files from OneDrive for business site using Sync Option

Let me show you how to download all your files from OneDrive so that you have a local copy on your computer with the Sync option. This way, you’ll always be able to access your files, even if there is an issue with OneDrive or the internet connection.

  1. Browse to the OneDrive site which you would like to download files from.
  2. Click on “Sync” button in the toolbar (Make sure you have OneDrive client installed in your local machine). This will start the sync process from OneDrive to your local disk. download all files from onedrive for business
  3. Open the File Explorer, Locate the Folder created from the sync operation under “YourDomain” node, Right-click on the folder and choose “Always keep on this device”. This starts downloading everything from the OneDrive instead of just establishing the sync link.download all onedrive files locally

Option 3: PowerShell to Download OneDrive for Business

Do you ever find yourself needing to download files from OneDrive for Business, but don’t want to go through the web interface? Well, there’s a PowerShell way for that! Here is how to use the PowerShell script to easily download files from OneDrive for Business:

#Parameters
$OneDriveSiteURL = "https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com"
$DownloadPath ="C:\Temp\OneDrive"

Try {
    #Connect to OneDrive site
    Connect-PnPOnline $OneDriveSiteURL -Interactive
    $Web = Get-PnPWeb

    #Get the "Documents" library where all OneDrive files are stored
    $List = Get-PnPList -Identity "Documents"
 
    #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 OneDrive:" -Status "Processing Items $global:Counter to $($List.ItemCount)";} 
    Write-Progress -Activity "Completed Retrieving Files and Folders from OneDrive!" -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
        $LocalFolder = $DownloadPath + ($_.FieldValues.FileRef.Substring($Web.ServerRelativeUrl.Length)) -replace "/","\"
        #Create Local Folder, if it doesn't exist
        If (!(Test-Path -Path $LocalFolder)) {
                New-Item -ItemType Directory -Path $LocalFolder | Out-Null
        }
        Write-host -f Yellow "Ensured Folder '$LocalFolder'"
    }
 
    #Get all Files from the folder
    $FilesColl =  $ListItems | Where {$_.FileSystemObjectType -eq "File"}
 
    #Iterate through each file and download
    $FilesColl | ForEach-Object {
        $FileDownloadPath = ($DownloadPath + ($_.FieldValues.FileRef.Substring($Web.ServerRelativeUrl.Length)) -replace "/","\").Replace($_.FieldValues.FileLeafRef,'')
        Get-PnPFile -ServerRelativeUrl $_.FieldValues.FileRef -Path $FileDownloadPath -FileName $_.FieldValues.FileLeafRef -AsFile -force
        Write-host -f Green "Downloaded File from '$($_.FieldValues.FileRef)'"
    }
}
Catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

This PowerShell script backup the OneDrive for Business to your local computer.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

18 thoughts on “How to Download All Files from OneDrive for Business?

  • That is exactly what I needed, thanks again!

    Reply
  • Your site is amazing and this PowerShell script is great to download the entire documents library but do you have any code handy that could target specific subfolders in OneDrive? Or can explain the easiest way to accomplish this? I’m struggling…thanks in advance from this PS novice!

    Reply
  • I am downloading a 90 gb folder from Onedrive to a zip file (Download Option 1). The download progress bar shows how much has been downloaded so far. Does this information reflect the unzipped or the zipped amount? If it’s the zipped amount, what would the zipped size of of a file that was 90 gb before zipping be? I know that you cannot be precise but would appreciate some ballpark figure so I can have some idea of how long the download will take.
    How I wish the estimated time remaining were available!!!!!
    Thank you.

    Reply
  • HI Rajack,
    Thanks for sharing this code. I am often handling off-boarding requests at work, and it’d be of great use if I could get this to work for me. questions:

    1. Am I supposed to run this in ODFB powershell console, run as an admin?
    2. Can I add variables for capturing the departing user’s name as well as the name of the user to whom I’ll then can copy the downloaded data to?
    3. Can we add MFA support to the code; if needed?

    Am I supposed set these values?
    A. $DepartingUser, UPN of departing user
    B. $destinationuser, UPN of user to whom we are coping departing user’s data
    C. $GlobalAdmin, UPN of global admin with access to departing and destination libraries.

    If you have a few minutes and would not mind reviewing my code I could add it here.

    Thanks again for the great information shared in this page.

    Reply
    • Hi Hector,
      1. You can run it in Visual Studio Code or PowerShell console.
      2. Yes! You can copy files between OneDrive sites using PowerShell. Please refer to PowerShell examples in this site.
      2. Connect-PnPOnline with -Interactive switch is already MFA enabled!

      Reply
  • I used this but keep running into issues for files that don’t have an extension. Is there a workaround for this? It stops each time I run into these errors.

    Reply
  • Thanks so much for the great information! Will the PowerShell code in Option 3 work with my Personal Microsoft 365 subscription and OneDrive? Also, do it recreate all of the folders and sub folders just like it is currently setup in my OneDrive when it copies to a local HDD? Thanks in advance for your help and assistance in this regard.

    Reply
  • Is there a way to automate the login and give it pre-define credentials?

    Reply
  • The download function seems to fail if the zip file gets too big. I tried to download everything from a multi-gigabyte OneDrive account and the zip file stopped downloading after around 1.4GB.

    Reply
    • Looks like that was a Chrome browser limit. Downloading in Edge has a 20GB limit for multiple folders, and apparently a 250GB limit if you get just one folder.

      Reply
  • Hi,
    How to download all the users using the script in power chaning the variables these two variable.
    $OneDriveSiteURL = “https://crescent-my.sharepoint.com/personal/salaudeen_crescent_com”
    $DownloadPath =”C:\Temp\OneDrive”
    I have 600 users onedrive to download.

    Thanks for the help.
    Kiko

    Reply
    • Hi Kiko,

      1. You can get all OneDrive for Business sites: $OneDriveSites = Get-SPOSite -Template “SPSPERS” -limit ALL -includepersonalsite $True
      2. Wrap the above code into a function and call the function for each site.

      Reply
  • No option to keep folders “on this device”. Only works for files. MS is dumb..

    Reply
    • Has this worked for any of you? Does the user under whose profile the script runs under, must be a member of the Sharepoit global admins’ group?

      I also want to know if the code must be run from the server under the domain admin user’s account, or can it be run from a normal user’s account, and provide domain admin creds when prompted?

      Thanks

      Reply
      • This script can be run from anywhere, including your client machine. The user running this script must be A site collection Admin or owner of the particular OneDrive.

        Reply
  • April 12 > the download Link has been removed!!! ugg

    Reply

Leave a Reply

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