Get Shortcut contents in Powershell


Some applications create a lot of shortcuts and sometimes you wonder what differences between them are. Or they are created at a locatoin you don’t find practical and want to create them elsewhere. You could click on each shortcut and copy paste the information but so let’s see how to get shortcut contents in Powershell so we can automate that.

Manipulating the shortcuts is part of the shell responsibilities, so we will need to instantiate a Wscript.Shell COM Object. In this example, we are retrieving the first shortcut found in the Start Menu of All users

Then you will need to point at the .lnk file and use the CreateShortcut method. Despite its name the CreateShortcut method is not meant to create the lnk file but rather create a representation of the shortcut as an object. You get then various properties of a WshShortcut object  whose most interesting ones are the TargetPath and the Arguments values.

A complete example here is the output of the different shortcuts created by Visual Studio 2017 for the developer tool prompts.

If you were to create or update a  lnk shortcut file on Windows, you would still use CreateShortcut to manipulate the object, set up the properties and then you would zuse the Save() method to record the change into a newly create or  existing .lnk file

Leave a comment

Your email address will not be published. Required fields are marked *