Download Multiple Documents From SharePoint Using PnP PowerShell

In this blog, we are going to see how to download the documents from SharePoint based on a specified URL using PnP PowerShell. 

Syntax
  1. Get-PnPFile -AsFile [<SwitchParameter>]  
  2.             -Url <String>  
  3.             [-Path <String>]  
  4.             [-Filename <String>]  
  5.             [-Force [<SwitchParameter>]]  
  6.             [-Web <WebPipeBind>]  
  7.             [-Connection <SPOnlineConnection>]  

Reference

https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/Get-PnPFile.md

The above Get-PnPFile command with –AsFile parameter is used to download the document based on the URL. The below PnP PowerShell script downloads the specified files from SharePoint library to the local path.
  1. $cred = Get-Credential  
  2. Connect-PnPOnline -Url https://<tenant>.sharepoint.com/sites/dev -Credential $cred  
  3.   
  4. $files = "/sites/dev/Shared%20Documents/DemoDocument1.docx","/sites/dev/Shared%20Documents/profile.docx"  
  5. $files | ForEach {  
  6. $s = $_.split("/"); $l=$s.length;  
  7. $fn = $s[$l-1];  
  8. Get-PnPFile -Url $_ -Path E:\ktskumar\Downloads -FileName $fn -AsFile  
  9. }  

The above snippet downloads the DemoDocument1.docx and profile.docx to the local machine under E:\ktskumar\Downloads path. 

Output