2

Hi why do I receive a file not found error when downloading a file from SharePoint Online using Get-PnpFile in PowerShell even though I can get its details on my first line of code below:

enter image description here

enter image description here

I just simply followed the code here: https://github.com/SharePoint/PnP-Guidance/blob/master/powershell/GetPnPFile.md

I am a site collection admin to the site but still no luck.

Any help is appreciated.

  • Why do you add -AsFile in the end? Does c:\temp contain your file? Do you have write permissions to this folder? – AlexZh Jun 6 '18 at 6:53
  • Hi I just followed the code on the link from Github. I tried to remove -AsFile see my updated post it prompts me to supply new value. For C:\ temp is my local drive and have admin privileges. – BizApps Jun 6 '18 at 7:04
  • Try -AsFile $false. – AlexZh Jun 6 '18 at 7:08
1

Make sure to use decoded Url path and for the safety purpose, please include the path under quotes. I have tried this command and it worked like a charm

Get-PnPFile -ServerRelativeUrl "/sites/PSD-Dev/Bulk Docs Library/Folder Level 1/Folders With Files/SubFolderFile1/sample File No- 2.txt" -Path D:\DvG -Filename "sample File No- 2.txt" -AsFile

PS: I am using pnp powershell version '2.26.1805.1' Run this command to update to latest pnp-powershell version

install-module sharepointpnppowershellonline -Force
| improve this answer | |
  • I'm using the same version. I saw some post that this only work if you are a tenant admin. – BizApps Jun 6 '18 at 7:47
  • In this case I am only a site coll admin.. not a tenant admin – DvG Jun 6 '18 at 7:52
  • Also, you can check if you have set up the set-executionpolicy remotesigned ..for ur machine – DvG Jun 6 '18 at 7:54
  • I got this error: Get-ExecutionPolicy : Cannot bind parameter 'Scope'. – BizApps Jun 6 '18 at 8:05
  • Follow this: for setting the execution policy docs.microsoft.com/en-us/powershell/module/… . Let me know if any issue? – DvG Jun 6 '18 at 8:25
2

I had this issue. It worked if I used a " " instead of the %20 in the url.

After debugging the code I found that the issue was with the GetFileByServerRelativePath(ResourcePath.FromDecodedUrl(serverRelativeUrl) call that Get-PnpFile uses when downloading the file. I then stumbled on this: https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/supporting-and-in-file-and-folder-with-the-resourcepath-api.

Get-PnpFile doesn't treat the URL in this way if fetching the file object so confusingly, the %20 is fine in the URL for that type of call.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.