In the Documents directory in Sharepoint online I have a sub-directory called Development and a file in there called FontDemoInfo.txt.

In the browser it looks like:

Documents > Development  FontDemoInfo.txt

How do I get that file with the Get-PnPFile command?

I connect to the Office365 Sharepoint with:

Install-Module SharePointPnPPowerShellOnline
Connect-PnPOnline  "https://company.sharepoint.com/sites/Company"

Where company and Company are the (case-sensitive) default names set up for the site.

If I do Get-PnPFile -Url "/Development/FontDemoInfo.txt" -AsFile I get a File Not found. error.

I tried about 10 different combinations of url that I read about (e.g. prefixes with slash, no slash, /Documents, /sites, copy link from the browser etc) but I still can't get the file.

What is the correct way to get this document in Sharepoint using PnP PowerShell?

5 Answers 5


Did you try this

Get-PnPFile -Url "/sites/Company/Development/FontDemoInfo.txt" -AsFile

You need to use Get-PnPFile in below format:

Get-PnPFile -Url /sites/siteName/DocumentLibrary/Folder/file.extension -AsFile

For example:

Get-PnPFile -Url /sites/project/_catalogs/themes/15/company.spcolor -AsFile

This retrieves the file and returns it as a File object

Get-PnPFile -Url /sites/project/_catalogs/themes/15/company.spcolor -Path c:\temp -FileName company.spcolor -AsFile

This retrieves the file and downloads it to c:\temp\company.spcolor

You can find more information in documentation at: Get-PnPFile


The Url parameter should be the server relative url, in this case, the relative url is this:


The format was in other answers

Get-PnPFile -Url "/sites/Company/Development/FontDemoInfo.txt" -AsFile

The key part of these answers is the start /sites/Company/

The main problem in this case though comes from how SharePoint is displaying the information.

As per the question, the browser shows Documents > Development FontDemoInfo.txt

However, the Documents directory is misleading. Clicking on the file and inspecting the URL in the browser more closely shows that the directory is actually Shared Documents! I'm not sure why this is the case or why it isn't displayed like that in the browser.

Thus, to get this file the url is actually:

Get-PnPFile -Url "/sites/Company/Shared Documents/Development/FontDemoInfo.txt" -AsFile
  • Yes, the default Documents library's path is Shared Documents rather than Documents. Glad you are finding the correct answer, then you could accept your own reply as answer.
    – Jerry
    Commented Feb 6, 2021 at 17:06

Wasted 20 minutes on this, so putting in here in case it helps someone else - an fyi that this can also be caused if you've connected to the wrong site with Connect-PnPOnline (I was connecting to several sites for various operations and forgot to change to the correct site before using Get-PnPFile).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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