Create Shortcuts on Desktops using Powershell

Mostly we will simply copy an already created shortcut but With PowerShell you can create a shortcut by using the New-Object cmdlet. Let we look in to this detail below. Here’s a quick script to create a shortcut to Notepad and put it on the desktop.

Step #1: The First 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.

$SourceFileLocation = “$env:SystemRoot\System32\notepad.exe”
$ShortcutLocation = “C:\Users\thiyagu.a.selvaraj\Desktop\Notepad.lnk”

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

$WScriptShell = New-Object -ComObject WScript.Shell

Step #3: The third step is to add the target path to the method

$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $SourceFileLocation

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

$Shortcut.Save()

Final Code

# Create a Shortcut with Windows PowerShell
$SourceFileLocation = "$env:SystemRoot\System32\notepad.exe"
$ShortcutLocation = "C:\Users\thiyagu.a.selvaraj\Desktop\Notepad.lnk"
#New-Object : Creates an instance of a Microsoft .NET Framework or COM object.
#-ComObject WScript.Shell: This creates an instance of the COM object that represents the WScript.Shell for invoke CreateShortCut
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $SourceFileLocation
#Save the Shortcut to the TargetPath
$Shortcut.Save()

 

What do you think?

I hope you have an idea of  how to create the Create Shortcuts on Desktops using Powershell. I would like to have feedback from my posts readers. Your valuable feedback, question, or comments about this article are always welcome.

4 thoughts on “Create Shortcuts on Desktops using Powershell”

  1. Hello there, thank you:)

    Please let me know how i can add a shortcut of any app which i install from command prompt. Let say i have one ABC.exe app which i want to install and create a shortcut for the same on windows desktop.

    Shall i just say,
    “$env:SystemRoot\System32\ABC.exe” and run this command in powershell ?

  2. Good day, I have a program that needs the ” ” taken out of the target path how do you remove that out of the target box. it is not just as simple as to remove them from the script

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.