PowerShell script to create shortcut on desktop with icon

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:

  1. 6 Steps to create a shortcut in PowerShell.
  2. 3 Steps to create PowerShell shortcut to ShutDown Computer.
  3. Verdict.

People also search for:

Shut Down yours and multiple remote computers using PowerShell

create a shortcut in PowerShell
  • The created shortcut is shown in the image.
    The created shortcut in PowerShell
  • 3 steps to create PowerShell Shortcut to Shutdown computer:

    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.

      1. We need the Microsoft Edge icon. We can right-click the below icon and use save as option to save it to the Downloads folder. Please note that you have to save it to the Downloads folder.
        icon image
      2. Open the PowerShell terminal and enter the following script.
        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[]
      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.Shells 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.

    Video liên quan

    Chủ Đề