Home » PowerShell » Create Shortcut on User Desktop using PowerShell

Create Shortcut on User Desktop using PowerShell

In this post, I will explain you how to use PowerShell script to create shortcut for file, folder or application in PowerShell.

Few days ago, I had a requirement to create shortcut for application on all active directory users desktop machine. There has been many ways to create shortcut for application, file or folder. I found PowerShell script best fit to create shortcut with PowerShell.

PowerShell Create Shortcut to File

Let’s consider a requirement to create a shortcut for Microsoft Edge using PowerShell script.

Let’s look at given below PowerShell script to create shortcut for Microsoft Edge on desktop. You must have the Windows Script host on your computer to run the below script.

Step #1 Define source file location of Microsoft Edge

	$SourceFilePath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"

Cool Tip: Query Active Directory users info using PowerShell!

Step #2: Define shortcut file location and name of shortcut file.

When we run entire PowerShell script, it will create shortcut file to the user desktop with provided name. Shortcut file has extension .lnk

$ShortcutPath = "C:\Users\Gary.Thomas\Desktop\MsEdge.lnk"

Step 3: Create new WScript.Shell object and assign it to variable

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

Step #4: Create Shortcut using shortcut path specified in Step 2

$shortcut = $WscriptObj.CreateShortcut($ShortcutPath)

Step #5: Add Target Path or other relevant arguments to shortcut variable

$shortcut.TargetPath = $SourceFilePath

Cool Tip: How to map network drive in PowerShell!

Step #6: Use Save() method

$shortcut.Save()

Above program demonstrates, using PowerShell to create shortcut on desktop for user.

Step #7: PowerShell Create Shortcut Code

$SourceFilePath = "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
$ShortcutPath = "C:\Users\Gary.Thomas\Desktop\MsEdge.lnk"
$WScriptObj = New-Object -ComObject ("WScript.Shell")
$shortcut = $WscriptObj.CreateShortcut($ShortcutPath)
$shortcut.TargetPath = $SourceFilePath
$shortcut.Save()

Cool Tip: Do you know how to get free disk space using PowerShell!

PowerShell Create shortcut to Folder

In this example, I will explain you how to create shortcut to folder on user desktop or on remote computer with PowerShell.

Let’s consider, we have to create a shortcut to folder available on D:\ drive and save shortcut on user desktop.

Copy below PowerShell script and run it on your computer to create shortcut with PowerShell.

$SourceFilePath = "D:\PowerShell\"
$ShortcutPath = "C:\Users\admin\Desktop\powershell.lnk"
$WScriptObj = New-Object -ComObject ("WScript.Shell")
$shortcut = $WscriptObj.CreateShortcut($ShortcutPath)
$shortcut.TargetPath = $SourceFilePath
$shortcut.WindowStyle = 1
$ShortCut.Hotkey = "CTRL+SHIFT+T";
$shortcut.Save()

In the above PowerShell script, first we define location and path for shortcut folder.

Later, we create an object of WScript and assign it to variable. We have added TargetPath, WindowsStyle and HotKey to shortcut variable.

Upon invoking Save() method, it create a shortcut on user desktop for folder. You can use use CTRL+SHIFT+T to open the folder.

Cool Tip: Best way to download zip file using PowerShell!

Conclusion

I hope above article helps you to understand how to create a shortcut in PowerShell for application, file or folder.

If you have requirement to create a shortcuts on active directory users or multiple remote computers, above post and PowerShell script will be very much useful to automate the process.

You can find more topics about PowerShell Active Directory commands and PowerShell basics on ShellGeek home page.

Cool Tip: Learn about how to unzip file to folder using PowerShell!