Using PowerShell to Create a Shortcut
PowerShell's New-Object -Com Creates a Shortcut
The purpose of this page is to explain how to create a shortcut on your desktop. The method we will be using is, New-Object -ComObject WScript.Shell.
Topics for PowerShell Creates Desktop Shortcut
All PowerShell COM objects are rely on the basic command: New-Object -Com. For our mission to create a shortcut we need a WScript.Shell type of comObject. As usual, I will take you step-by-step through the method.
1) Assuming You Have
2) Create the Object (WScript.Shell)
# Windows PowerShell Com Object
3) Research the Methods with Get-Member
# Research WScript.Shell Methods
The above is how I discovered the .CreateShortcut method. Let us now see how we can build a shortcut on the desktop.
4) Build a Shortcut Shell
Problem: This example below merely creates a shell, we are going to need properties for a fully functioning shortcut see 5) Create Shortcut.
# Build a Shortcut Shell
Note 1: $Home\Desktop specifies the location for the shortcut, this translates to the desktop of the current user.
Note 2: Here are the shortcut properties some of which are vital to build a functioning shortcut.
This example uses PowerShell to create a shortcut for calc.exe on your desktop. You could substitute the name of another executable, or if you prefer type the full path to the program you want to launch via a desktop shortcut.
# Create a Calculator Shortcut with Windows PowerShell
Note 3: Nothing much happens unless you append the .Save() method.
Note 4: It's essential to put the name of the application "Calc", or the path, in double speech marks.
Windows Management Instrumentation (WMI) is one of the hidden treasures of Microsoft's operating systems. Fortunately, SolarWinds have created a Free WMI Monitor so that you can discover these gems of performance information, and thus improve your PowerShell scripts.
Take the guess work out of which WMI counters to use when scripting the operating system, Active Directory, or Exchange Server. Give this WMI monitor a try - it's free.
The purpose of this script is to create a different shortcut, one which allows you to remove USB hardware quickly, but safely.
PowerShell Script to Create a Shortcut
$AppLocation = "C:\Windows\System32\rundll32.exe"
Note 5: This example employs more properties, for example, .Arguments and .IconLocation.
Troubleshooting PowerShell Create Shortcut
Another source of troubleshooting a shortcut that PowerShell did not make correctly is to compare the failure with the properties of a shortcut you successfully created manually. My idea is to match up the properties as researched with Get-Member with boxes such as Target, or Start in.
SolarWinds' Network Performance Monitor will help you discover what's happening on your network. This utility will also guide you through troubleshooting; the dashboard will indicate whether the root cause is a broken link, faulty equipment or resource overload.
What I like best is the way NPM suggests solutions to network problems. Its also has the ability to monitor the health of individual VMware virtual machines. If you are interested in troubleshooting, and creating network maps, then I recommend that you try NPM now.
How to List Shortcuts
Here is a script to list shortcuts on Microsoft's Start Menu
# List all .lnk files and their image paths
Summary of PowerShell Create Shortcut Script
I have employed the New-Object cmdlet to mimic what you do manually when creating a shortcut on the desktop. Because it's trickier than you might suspect, I have built-up gradually, in particular, I explained how to research the methods and properties.
If you like this page then please share it with your friends
See More Windows PowerShell Examples of Real-life Tasks
Please email me if you have a better example script. Also please report any factual mistakes, grammatical errors or broken links, I will be happy to correct the fault.