Live training: next batches coming soon. Join the waitlist:Waitlists open:Developer Training →Developer →Copilot Studio Training →Copilot Studio →

Download All Files from a SharePoint Document Library Using PnP PowerShell

A finance manager once asked me to hand over a full copy of a document library before a site was archived. It had about 9,000 files in nested folders. The browser’s Download button zipped for a while, then failed, and the partial zip was missing whole folders.

That’s when PowerShell earns its keep. Below are the PnP PowerShell scripts I use to download every file from a SharePoint Online library, keep the folder structure, filter by type, size, date, user or column, survive throttling and prove nothing was skipped.

Quick answer: Connect with Connect-PnPOnline -Url <site> -ClientId <your-app-id> -Interactive, read every file with Get-PnPListItem -List "Documents" -PageSize 2000, keep the items where FileSystemObjectType is File, and save each one with Get-PnPFile -Url $Item.FieldValues.FileRef -Path <local folder> -Filename $Item.FieldValues.FileLeafRef -AsFile -Force.

Before you start: PowerShell 7, PnP PowerShell and an Entra ID app

Why not just use the browser? Its multi-file download builds a zip, and Microsoft caps that at 10,000 files, with compressed files such as .zip or .mp4 limited to 10 GB each and 20 GB overall. A script has no such cap, can resume, and leaves a log.

Current PnP PowerShell needs PowerShell 7 (version 3.x asks for 7.4 or later), so it won’t load in Windows PowerShell 5.1. Check your version, then install the module. My guide to installing PnP PowerShell for SharePoint Online covers the other install options.

$PSVersionTable.PSVersion
Install-Module -Name PnP.PowerShell -Scope CurrentUser -Force
Get-Module PnP.PowerShell -ListAvailable | Select-Object Name, Version

You also need at least Read access to the library. The bigger hurdle is the sign-in: since September 9, 2024, Connect-PnPOnline requires a -ClientId from an Entra ID app registered in your own tenant. Register one once and reuse its ID everywhere:

Register-PnPEntraIDAppForInteractiveLogin -ApplicationName "PnP Rocks" -Tenant contoso.onmicrosoft.com -Interactive

Note: Register-PnPEntraIDAppForInteractiveLogin has no -Interactive parameter, so this line stops with “A parameter cannot be found that matches parameter name ‘Interactive'”. Drop -Interactive (the browser sign-in is the default) or swap it for -DeviceLogin. Creating the app usually needs an Application Administrator, and granting consent a Global Administrator.

Now connect to the site and confirm the session works. If anything here fails, my walkthrough on connecting to SharePoint Online using PowerShell explains every sign-in method and error.

$SiteURL  = "https://contoso.sharepoint.com/sites/Finance"
$ClientId = "11111111-2222-3333-4444-555555555555"

Connect-PnPOnline -Url $SiteURL -Interactive -ClientId $ClientId
Get-PnPWeb | Select-Object