Recently, I got a requirement to download a file from a document library in SharePoint. For this, I use PnP PowerShell. I will show you how to download files from a SharePoint document library using PnP PowerShell in this tutorial.
I will show you how to download a single file from a SharePoint Online document library using PnP PowerShell. Also, I will show you how to download multiple files from a SharePoint document library using PnP PowerShell.
Download a File from SharePoint Document Library Using PnP PowerShell
To download a single file from a SharePoint document library using PnP PowerShell, you will need to specify the path to the file in the library and the local path where you want to save the file. Here’s the complete code:
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive
$libraryName = "HRDocuments"
$fileName = "MyWordFile.docx"
$localPath = "C:\Downloads\"
# Get the file
$file = Get-PnPFile -Url "/$libraryName/$fileName" -Path $localPath -FileName $fileName -AsFile
Write-Host "File downloaded to $localPath"Once you execute the above PowerShell script, it downloads the document from the SharePoint Online document library and saves it in my local folder.

Read Download File from URL in PowerShell
Download Multiple Files from SharePoint Document Library Using PnP PowerShell
Now, let me show you how to download multiple files from a SharePoint document library using PnP PowerShell.
Below is the PnP PowerShell script to download all the files from the document library in SharePoint Online.
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"
Connect-PnPOnline -Url $siteUrl -Interactive
# Define the library and local download path
$libraryName = "HRDocuments"
$localFolderPath = "C:\Downloads\"
# Ensure the local folder exists
if (-Not (Test-Path -Path $localFolderPath)) {
New-Item -ItemType Directory -Path $localFolderPath
}
# Get all files from the library
$files = Get-PnPListItem -List $libraryName | Where-Object { $_.FileSystemObjectType -eq "File" }
foreach ($file in $files) {
$fileUrl = $file.FieldValues.FileRef
$fileName = $file.FieldValues.FileLeafRef
$localFilePath = Join-Path -Path $localFolderPath -ChildPath $fileName
# Download the file
Get-PnPFile -Url $fileUrl -Path $localFolderPath -FileName $fileName -AsFile
Write-Host "File $fileName downloaded to $localFolderPath"
}Once you execute the above PowerShell script, it will download all the files to the local folder. You can see the output in the screenshot below, after I executed the above PowerShell script.

If you want to download files in bulk from a SharePoint Online document library using PnP PowerShell, then I hope the above complete script will be helpful.
Conclusion
In this tutorial, I have explained how to download a single file from a SharePoint Online document library using PnP PowerShell and how to download multiple files from a document library using PnP PowerShell in SharePoint Online.
You may also like the following tutorials:
- Import Data from Excel to SharePoint List using PnP PowerShell
- Delete All Items from a SharePoint List using PnP PowerShell
- Upload Files to a SharePoint Document Library using PnP PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.