PowerShell is a powerful scripting tool used to perform administrative tasks. Being a scripting tool, it allows the users to create different types of scripts and create functions, such as creating shortcuts. Normal PowerShell does not support scripting, and it only permits the running of single-line commands. In order to run and create scripts on Windows, PowerShell has introduced a scripting host by the name of the “PowerShell ISE”. It comes pre-installed in every latest version of Windows.
This post will overview a complete guide to resolve the mentioned query.
How to Create a Shortcut Using PowerShell?
We have compiled a list of steps to guide you through creating a shortcut on the desktop using PowerShell.
Step 1: Create a New Wscript.Shell Object and Assign it to the Variable
In the first step, we will create a new object/script and assign it to the variable as demonstrated:
Here, “WScript.Shell” provides access to the operating system objects.
Step 2: Define the Destination/Location of the Shortcut
In the second line, define the path for a shortcut:
Step 3: Define the Target Path
Now, define the path for the application to create a shortcut:
Step 4: Save the Shortcut
In the final step, execute the given command for running the script to create a shortcut:
Code
In our case, we will execute the given script for creating a desktop shortcut for the Notepad application named “notepad.lnk”:
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\notepad.lnk")
$Shortcut.TargetPath = "C:\WINDOWS\system32\notepad.exe"
$Shortcut.Save()
Output
In order to verify whether the shortcut was created or not. First, navigate to the Start menu, search and launch “PowerShell” and execute the given line of code:
Here the given “Get-ChildItem” command will fetch the child items of the specified desktop directory:
From the output, it can be observed that the “notepad.lnk” shortcut has been successfully created on the desktop.
Conclusion
To create a shortcut using PowerShell, first, create a “Wscript.Shell” object and assign it to a variable, define the directory/location to save the shortcut. After that, specify the location of the application/folder for which you want to create a shortcut. Finally, save and execute the script to create a shortcut. This post has demonstrated a detailed guide to creating a shortcut using PowerShell.