Is it possible to get document from SharePoint Online document library by link URL, that is generated from UI with "Get link" functionality in PowerShell? enter image description here

Link example: https://contoso.sharepoint.com/:w:/g/EcsPC4X-lvtGp-c_5QOee_cJSccfFS0aFvdPLxIr19MMPQ

  • You can get bit cleaner link to the document, see my answer here. – Ganesh Sanap Feb 22 '19 at 14:05

Recently found the solution by myself (partly using PnP) - function GetFileByUrl does the job.


$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://contoso.sharepoint.com/:w:/g/EcsPC4X-lvtGp-c_5QOee_cJSccfFS0aFvdPLxIr19MMPQ")
Write-Host "Item:" $item.Name

$ctx = $null

Write-Host "End" -f Green -b DarkGreen
Write-host " "
Write-host " "

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.