How can I use the Get-PnPFile or Get-PnPListItems commands to get data from a URL with the structure /_layouts/15/Doc.aspx?sourcedoc=?

Jairo Javier Baleta Cali 216 Reputation points
2024-09-25T14:26:15.6633333+00:00

Good morning.

I hope you are.

I am trying to get information from files that are in SharePoint document libraries. But many of the URLs I have have the following structure:

https://<tenant>.sharepoint.com/:w:/r/sites/<site url>/_layouts/15/Doc.aspx?sourcedoc=xxxxx-xxxx-xxxx-xxxxx&file=xxxxxxxxxxxxx.docx&action=default&mobileredirect=true

I have not been able to use the sourcedoc or file parameter with the Get-PnPFile or Get-PnPListItems commands.

Is there any way I can get information with SharePoint Online PnP commands from a file that has a URL with this structure?

I hope you can help me.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,715 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,526 questions
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 35,556 Reputation points Microsoft Vendor
    2024-09-26T01:23:42.2533333+00:00

    Hi @Jairo Javier Baleta Cali

    Could try to use GetFileByUrl to resolve the issue. Please refer to following script

    $credential = Get-Credential
    Connect-PnPOnline –Url "https://contoso.sharepoint.com" –Credentials $credential
    $ctx = Get-PnPContext  
    $web = Get-PnPWeb 
    Write-Host "Web: " $web.Url
    $item = $web.GetFileByUrl("https://<tenant>.sharepoint.com/:w:/r/sites/<site url>......")
    $ctx.Load($item)
    $ctx.ExecuteQuery()
    Write-Host "Item:" $item.Name
    $ctx = $null
    
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Michael Taylor 54,401 Reputation points
    2024-09-25T14:47:54.21+00:00

    There is no Get-PnPFile command for SharePoint that I'm aware of. Are you referring to the third party library PnP? If so then you need to contact the developers of that library as they can better support you.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.