Using Powershell 6.0 :- Create shortcuts using scripting lnk or url files

Create shortcuts using scripting and its simply .lnk files with a few details.

Using PowerShell you can create a shortcut

We used New-Object commandlet.

Lets follow step by step to create shortcuts

Step #1: The first step is to create a variable referencing a Wscript.Shell COM Object.

Example



$Shell = New-Object -ComObject ("WScript.Shell")

Copy and Try it

Step #2: The second step is to define the location and name of your shortcut. The following example will add the shortcut to the user’s desktop with a name of Your Shortcut.

Example

$Shell = New-Object -ComObject ("WScript.Shell")
$ShortCut = $Shell.CreateShortcut($env:USERPROFILE + "\Desktop\Your Shortcut.lnk")

Copy and Try it

Step #3: The third step is to add the target path, any relevant arguments, along with anything else that may be required.

Example

$Shell = New-Object -ComObject ("WScript.Shell")
$ShortCut = $Shell.CreateShortcut($env:USERPROFILE + "\Desktop\Your Shortcut.lnk")
$ShortCut.TargetPath="yourexecutable.exe"
$ShortCut.Arguments="-arguementsifrequired"
$ShortCut.WorkingDirectory = "c:\your\executable\folder\path";
$ShortCut.WindowStyle = 1;
$ShortCut.Hotkey = "CTRL+SHIFT+F";
$ShortCut.IconLocation = "yourexecutable.exe, 0";
$ShortCut.Description = "Your Custom Shortcut Description";

Copy and Try it

Step #4: The final step is to envoke the Save() method to save your shortcut.

Example

$Shell = New-Object -ComObject ("WScript.Shell")
$ShortCut = $Shell.CreateShortcut($env:USERPROFILE + "\Desktop\Your Shortcut.lnk")
$ShortCut.TargetPath="yourexecutable.exe"
$ShortCut.Arguments="-arguementsifrequired"
$ShortCut.WorkingDirectory = "c:\your\executable\folder\path";
$ShortCut.WindowStyle = 1;
$ShortCut.Hotkey = "CTRL+SHIFT+F";
$ShortCut.IconLocation = "yourexecutable.exe, 0";
$ShortCut.Description = "Your Custom Shortcut Description";
$ShortCut.Save()

Copy and Try it

Step #5: As a bonus here is how you would create a Favorite in Windows which is a .url shortcut.

Example

$Shell = New-Object -ComObject ("WScript.Shell")
$Favorite = $Shell.CreateShortcut($env:USERPROFILE + "\Desktop\Your Shortcut.url")
$Favorite.TargetPath = "http://www.exampleurl.com";
$Favorite.Save()
    

Copy and Try it