Get target of shortcut (.lnk) file with powershell

You have made an error in the property; as wOxxOm suggests, you should be using TargetPath rather than Target:

$sh = New-Object -ComObject WScript.Shell
$target = $sh.CreateShortcut('<full-path-to-shortcut>').TargetPath

Google and MSDN were indeed helpful here; additionally, piping objects to Get-Member can often be useful and educational. This question also shows how to manipulate shortcuts using PowerShell, and uses the same technique as seen here.

If you want the arguments to the executable as well, those are stored separately:

$arguments = $sh.CreateShortcut('<full-path-to-shortcut>').Arguments

Again, piping objects to Get-Member – in this case, the object returned by WScript.Shell.CreateShortcut() – provides useful information.

It should be noted that there are issues with using this technique and these calls when the path contains Unicode emoji characters; there is a workaround for this case in this StackOverflow question.

Leave a Comment