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:
- Using Graph Explorer: https://developer.microsoft.com/en-us/graph/graph-explorer
1. Ensure that you have the Files.ReadWrite.All permission
2. Encode your URL in Base64 using the following PowerShell script:
1 2 3 4 |
$sharingUrl = "https://pbnet.sharepoint.com/:b:/s/BLABLA1/EXZD4nQEQEpLv2pPl-btZnkB3FrKUYbP7jXCEveeY_WfYA?e=hJCcWh" $base64Value = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($sharingUrl)) $encodedUrl = "u!" + $base64Value.TrimEnd("=").Replace("/", "_").Replace("+", "-") Write-Host $encodedUrl |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
Import-Module Microsoft.Graph.Files Connect-MgGraph -Scopes "Files.ReadWrite.All" # Set the sharing URL $sharingUrl = "https://pbnet.sharepoint.com/:b:/s/BLABLA1/EXZD4nQEQEpLv2pPl-btZnkB3FrKUYbP7jXCEveeY_WfYA?e=hJCcWh" $base64Value = [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($sharingUrl)) $encodedUrl = "u!" + $base64Value.TrimEnd("=").Replace("/", "_").Replace("+", "-") # Construct the Graph API request URL $requestUrl = "https://graph.microsoft.com/v1.0/shares/$encodedUrl/driveItem?$expand=children" $response=Get-MgShareDriveItem -SharedDriveItemId $encodedUrl -ExpandProperty "children" # Output the file details $response | Format-List |
The PowerShell output will be similar to:
Enjoy!