0

I'm trying to download files being edited in Microsoft Teams/Sharepoint Online using various examples from the Internet (including the ones here). Currently I am using the Sharepoint PnP module: https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/?view=sharepoint-ps

But all I am getting is "Get-PnPFile : File Not Found."

$cn = Connect-PnPOnline -Url $Site -ReturnConnection
Get-PnPFile -AsFile -Connection $cn -Url $Url -FileName $FileName -Path $Path

I am using the link to a file (that people are collaborating in Teams on) copied from the Sharepoint website (following the link from Teams, then getting the link from the file itself) which comes in the form https://oursite.sharepoint.com/:x:/s/foldernamefromteams/longidentifier I've tried passing that Url with and without the site name. I don't get an error on the Connect line. It pops up the username and password prompt.

I think the key is getting the site and/or URL correct, but I don't know how to get the correct URL other than from the link that Sharepoint says is the link to the file. Pasting that link in the browser does open the Excel sheet (or whatever) for editing in the browser, instead of downloading the file, but I'm not sure what a more "direct" link would be, or how to get it.

2
  • most probably url needs to be server-relative, so try removing https://oursite.sharepoint.com from the url...
    – Nils
    Jun 13, 2019 at 14:19
  • @Nils Yes, I have tried it both ways and also both ways using it as either the -Url or the -ServerRelativeUrl parameter
    – Cade Roux
    Jun 13, 2019 at 14:25

1 Answer 1

1

The Link that looks like https://oursite.sharepoint.com/:x:/s/foldernamefromteams/longidentifier is the link to the office online server to edit the document. You can not "download" that. You'd need the direct url to the file in SharePoint.

If you're using teams: Open teams, right-klick the file and select "get link" it should look like: https://[tenant-name].sharepoint.com/sites/[team-name]/documents/[channel-name]/[file-name.ext] use that with pnp.

Using that url (i.e. https://[tenant-name].sharepoint.com/sites/[team-name]/documents/[channel-name]/[file-name.ext]) you can download the file as follows:

Connect-PNPOnline https://[tenant-name].sharepoint.com/sites/[team-name]
Get-PNPFile -Url /sites/[team-name]/documents/[channel-name]/[file-name.ext] -AsFile
2
  • I did end up finding a URL which worked with actual friendly names of the form: https://[tenant].sharepoint.com/sites/[team]/Shared Documents/[folders]/[filename] - where Shared Documents is apparently the correct stand-in for the "Documents" that appears in the interface (and [team] can have a friendly description on the interface which varies from the actual path - in our case extra spaces on the web page)
    – Cade Roux
    Jun 14, 2019 at 19:48
  • Using Teams to find the link as you sugges, however, I either get a "Microsoft Teams" link of form teams.microsoft.com/l/file/B60BA4C8... or a Sharepoint link of the form: https://[tenant-name].sharepoint.com/sites/[TeamName]/_layouts/15/Doc.aspx?OR=teams&action=edit&sourcedoc={B60BA4C8 ...
    – Cade Roux
    Jun 14, 2019 at 19:48

Your Answer

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

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