[SPO] Get the filename, filetype and path from a SharePoint shared link URL

OK, so the scenario goes like this:

  • You go to a SharePoint document library, click on the ellipsis next to a file and select “Copy Link”

  • you will get a URL like: https://pbnet.sharepoint.com/:b:/s/BLABLA1/EXZD4nQEQEpLv2pPl-btZnkB3FrKUYbP7jXCEveeY_WfYA?e=hJCcWh

OK, now for the funny part, how can you know from that URL, what the file name is and where it is located.

If you use my tool: https://whois.pbnet.ro/SPOLINKDECODER/ you can already get some basic information like:

For more information about the tool and what’s its logic, please see my GitHub page: https://github.com/pbnet/SharePointSharedLinkDecoder

Now here’s how to get way more information:

1. Ensure that you have the Files.ReadWrite.All permission

2. Encode your URL in Base64 using the following PowerShell script:

The result will be something like: u!aHR0cHM6Ly9wYm5ldC5zaGFyZXBvaW50LmNvbS86Yjovcy9CTEFCTEExL0VYWkQ0blFFUUVwTHYycFBsLWJ0Wm5rQjNGcktVWWJQN2pYQ0V2ZWVZX1dmWUE_ZT1oSkNjV2g

3. Go to Graph Explorer at: https://developer.microsoft.com/en-us/graph/graph-explorer

The syntax of the URL should be like:

https://graph.microsoft.com/v1.0/shares/<base64 shared link from PowerShell Script>/driveItem?$expand=children

So the final URL is like: https://graph.microsoft.com/v1.0/shares/u!aHR0cHM6Ly9wYm5ldC5zaGFyZXBvaW50LmNvbS86Yjovcy9CTEFCTEExL0VYWkQ0blFFUUVwTHYycFBsLWJ0Wm5rQjNGcktVWWJQN2pYQ0V2ZWVZX1dmWUE_ZT1oSkNjV2g/driveItem?$expand=children

And there you go… you have the weburl, name of the file and name of the library:

  • If you want to do this with Graph PowerShell and get the name of the file, the logic is similar to the script below:

The PowerShell output will be similar to:

Enjoy!