How to Create Desktop Shortcuts with Custom Icons Using PowerShell?

In this tutorial, I will explain how to create desktop shortcuts with custom icons using PowerShell. As an IT administrator, I recently faced the challenge of creating desktop shortcuts for various applications with specific icons on multiple user computers. Let me show you now how to do this.

Create Desktop Shortcuts with Custom Icons Using PowerShell

To create a desktop shortcut using PowerShell, we’ll use a script that uses the WScript.Shell object. Here’s a basic example of the script:

$TargetFile = "C:\Program Files\Mozilla Firefox\firefox.exe"
$ShortcutFile = "C:\Users\Public\Desktop\Firefox.lnk"
$IconLocation = "C:\Program Files\Mozilla Firefox\firefox.exe, 0"

$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.IconLocation = $IconLocation
$Shortcut.Save()

Let’s break down the script:

  1. $TargetFile: This variable specifies the path to the executable file for which you want to create the shortcut. In this example, it points to the Firefox executable.
  2. $ShortcutFile: This variable defines the path and name of the shortcut file that will be created on the desktop. Here, we’re creating a shortcut named “Firefox.lnk” in the Public Desktop folder.
  3. $IconLocation: This variable specifies the location of the icon file and its index. In this case, we’re using the default Firefox icon located within the Firefox executable.
  4. $WScriptShell: This line creates an instance of the WScript.Shell object, which is used to create the shortcut.
  5. $Shortcut: This variable represents the shortcut object created using the CreateShortcut() method of the WScript.Shell object.
  6. The remaining lines set the TargetPath and IconLocation properties of the shortcut object and save the shortcut file using the Save() method.

Check out Create a Self-Signed Certificate Using PowerShell

Customize the PowerShell Script

Now that you understand the basic script, let’s customize it to create shortcuts for different applications with custom icons. Here’s an example:

$TargetFile = "C:\Program Files\Google\Chrome\Application\chrome.exe"
$ShortcutFile = "C:\Users\Public\Desktop\Google Chrome.lnk"
$IconLocation = "C:\Program Files\Google\Chrome\Application\chrome.exe, 0"

$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile
$Shortcut.IconLocation = $IconLocation
$Shortcut.Save()

In this example, we’re creating a shortcut for Google Chrome with its default icon. Simply adjust the $TargetFile, $ShortcutFile, and $IconLocation variables to match the desired application and icon.

You can also specify a separate icon file by modifying the $IconLocation variable. For example:

$IconLocation = "C:\Icons\CustomIcon.ico, 0"

This line sets the icon location to a custom icon file named “CustomIcon.ico” located in the “C:\Icons” directory.

Check out Disable Windows Firewall Using PowerShell

Execute the PowerShell Script

To run the PowerShell script and create the desktop shortcut, follow these steps:

  1. Open PowerShell as an administrator.
  2. Navigate to the directory where you saved the script file.
  3. Execute the script by running the following command:
   .\CreateShortcut.ps1

Replace “CreateShortcut.ps1” with the actual name of your script file.

  1. PowerShell will execute the script, and the desktop shortcut will be created with the specified target file and icon.

Check out Create a Local Admin Account Using PowerShell

Automate Shortcut Creation for Multiple Applications

To streamline the process of creating shortcuts for multiple applications, you can create a PowerShell script that defines an array of application details and iterates over them to create shortcuts. Here’s an example:

$Applications = @(
    @{
        TargetFile = "C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE"
        ShortcutFile = "C:\Users\Public\Desktop\Microsoft Word.lnk"
        IconLocation = "C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE, 0"
    },
    @{
        TargetFile = "C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE"
        ShortcutFile = "C:\Users\Public\Desktop\Microsoft Excel.lnk"
        IconLocation = "C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE, 0"
    },
    @{
        TargetFile = "C:\Program Files\Microsoft Office\root\Office16\POWERPNT.EXE"
        ShortcutFile = "C:\Users\Public\Desktop\Microsoft PowerPoint.lnk"
        IconLocation = "C:\Program Files\Microsoft Office\root\Office16\POWERPNT.EXE, 0"
    }
)

$WScriptShell = New-Object -ComObject WScript.Shell

foreach ($App in $Applications) {
    $Shortcut = $WScriptShell.CreateShortcut($App.ShortcutFile)
    $Shortcut.TargetPath = $App.TargetFile
    $Shortcut.IconLocation = $App.IconLocation
    $Shortcut.Save()
}

In this script, we define an array called $Applications that contains hash tables representing the details of each application. Each hash table includes the TargetFile, ShortcutFile, and IconLocation properties.

The script then iterates over the $Applications array using a foreach loop. For each application, it creates a shortcut using the WScript.Shell object, sets the TargetPath and IconLocation properties, and saves the shortcut file.

By running this script, you can automatically create desktop shortcuts for multiple applications with their respective icons in one go.

Create Desktop Shortcuts with Custom Icons Using PowerShell

Conclusion

In this tutorial, I explained how to create desktop shortcuts with custom icons using PowerShell. You also learned how to deploy shortcuts on multiple user computers using PowerShell. By using the WScript.Shell object, you can easily create shortcuts for various applications with specific icons.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.