In this blog, we are going to see how to download the documents from SharePoint based on a specified URL using PnP PowerShell.
Syntax
- Get-PnPFile -AsFile [<SwitchParameter>]
- -Url <String>
- [-Path <String>]
- [-Filename <String>]
- [-Force [<SwitchParameter>]]
- [-Web <WebPipeBind>]
- [-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.
- $cred = Get-Credential
- Connect-PnPOnline -Url https://<tenant>.sharepoint.com/sites/dev -Credential $cred
-
- $files = "/sites/dev/Shared%20Documents/DemoDocument1.docx","/sites/dev/Shared%20Documents/profile.docx"
- $files | ForEach {
- $s = $_.split("/"); $l=$s.length;
- $fn = $s[$l-1];
- Get-PnPFile -Url $_ -Path E:\ktskumar\Downloads -FileName $fn -AsFile
- }
The above snippet downloads the DemoDocument1.docx and profile.docx to the local machine under E:\ktskumar\Downloads path.
Output