0

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?

2

Did you try this

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

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

0

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

/sites/Company/Development/FontDemoInfo.txt
0

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
1
  • 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_MSFT Feb 6 at 17:06

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.