in

WindowsWindows Loving ItLoving It

[WORKING] Create Shortcut PowerShell | Shutdown Icon PowerShell

Use PowerShell and create shortcuts in Windows in 4 simple steps. Also use PowerShell to create an icon that helps users to shutdonw by clicking the icon.

PowerShell create shortcut

In this post, we are going to see various shortcut tips related to PowerShell.  Initially, we are going to see how to create a shortcut using the built-in shortcut command-let.  Then we will move on to other interesting things that we can do using the create shortcut command-let.

Jump to:

People also search for:

How to create a shortcut in PowerShell:

  • Step 1: Create variables to store the location of the executable and the destination location of the shortcut. Note that Event Viewer is located in System 32.

$SourceFileLocation = “$env:SystemRoot\System32\eventvwr.exe”
$ShortcutLocation = “C:\Users\$env:USERNAME\Desktop\Event Viewer.lnk”

  • Step 2: Create a new WScript.Shell object.

$WScriptShell = New-Object -ComObject WScript.Shell

  • Step 3: Pass the shortcut location and target file path to the WScript.Shell object.

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

  • Step 4: Save the shortcut.

$Shortcut.Save()

The code on the shell will look as follows.

create a shortcut in PowerShell

The created shortcut is shown in the image.

The created shortcut in PowerShell

Shutdown computer using PowerShell Shortcut:

We can take the shortcut solution to the next level using the shutdown command.  We will create a Microsoft Edge icon on the Desktop.  We will add a command to the icon such that on, clicking it, the system will shut down.  We have demonstrated it below.

step 1: We need to get the Microsoft Edge icon.  We can right-click the below icon and use save as it to the Downloads folder. Please note that you have to save it to the Downloads folder.

icon image
icon image

step 2: Open the PowerShell terminal and enter the following script.

$SourceFileLocation = “%windir%\System32\shutdown.exe”
$ShortcutLocation = “C:\Users\$env:USERNAME\Desktop\Microsoft Edge.lnk”
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutLocation)
$Shortcut.TargetPath = $SourceFileLocation
$Shortcut.IconLocation = “C:\Users\$env:USERNAME\Downloads\Microsoft-Edge.ico”
$Shortcut.Arguments = “/s /t 0”
$Shortcut.Save()

step 3: Try out the icon and see how the computer shuts down.

If you have completed the above steps correctly, you will be able to shut down the computer by clicking the edge icon.

Create shut down shortcut
Created shutdown shortcut

Verdict:

It is very easy to create a shortcut using PowerShell.  We use WScript.Shell’s create shortcut object to create a custom shortcut.  In the first part, we learned how to create a shortcut using a few simple steps.  In the second part, we created a shortcut that helps us shut down the computer using the shortcut.

If you want more such interesting posts, please stay tuned to TecKangaroo.

Leave a Reply

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