Complete Guide to Creating Shortcuts Using PowerShell

Nov 23, 2025 · Programming · 14 views · 7.8

Keywords: PowerShell | Shortcut | WScript.Shell | COM Object | Argument Passing

Abstract: This article provides a comprehensive guide on creating Windows shortcuts with PowerShell. Using WScript.Shell COM objects, users can flexibly set target paths, arguments, and other properties. The content covers basic creation methods, parameterized script implementation, argument passing techniques, and comparative analysis with symbolic links.

Fundamentals of PowerShell Shortcut Creation

In the Windows environment, PowerShell doesn't provide dedicated cmdlets for creating shortcuts, but this functionality can be achieved through COM objects. The WScript.Shell COM object offers a complete interface for creating and managing shortcuts.

Creating Shortcuts with WScript.Shell

The most basic shortcut creation method involves three key steps: creating a COM object instance, setting the target path, and saving the shortcut file.

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut("$Home\Desktop\ColorPix.lnk")
$Shortcut.TargetPath = "C:\Program Files (x86)\ColorPix\ColorPix.exe"
$Shortcut.Save()

This code first creates an instance of the WScript.Shell object, then calls the CreateShortcut method to specify the save path for the shortcut file, and finally sets the TargetPath property to the target executable file path and saves it.

Creating Reusable Parameterized Scripts

To improve code reusability, you can create a PowerShell script file that accepts parameters. This approach allows users to specify source executables and target paths through command-line parameters.

param (
    [string]$SourceExe,
    [string]$DestinationPath
)

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($DestinationPath)
$Shortcut.TargetPath = $SourceExe
$Shortcut.Save()

After saving as set-shortcut.ps1, it can be called in the following way:

Set-ShortCut "C:\Program Files (x86)\ColorPix\ColorPix.exe" "$Home\Desktop\ColorPix.lnk"

Adding Startup Argument Support

Shortcuts can not only point to executable files but also pass startup arguments. By setting the Arguments property, specific parameters can be passed to the target program when the shortcut is launched.

param (
    [string]$SourceExe,
    [string]$ArgumentsToSourceExe,
    [string]$DestinationPath
)

$WshShell = New-Object -comObject WScript.Shell
$Shortcut = $WshShell.CreateShortcut($DestinationPath)
$Shortcut.TargetPath = $SourceExe
$Shortcut.Arguments = $ArgumentsToSourceExe
$Shortcut.Save()

Setting the Arguments property before calling the Save method ensures that parameters are correctly saved to the shortcut file.

Differences Between Shortcuts and Symbolic Links

Although PowerShell 5.0 introduced symbolic link support, symbolic links are fundamentally different from shortcuts. Symbolic links work at the filesystem level, where all applications treat them as the original file, while shortcuts are special file types that require specific application support.

New-Item -ItemType SymbolicLink -Path "C:\temp" -Name "calc.lnk" -Value "c:\windows\system32\calc.exe"

Symbolic links are simpler to create but lack the rich functionality of shortcuts, such as custom icons, working directory settings, and more.

Advanced Features: Running with Administrator Privileges

By directly modifying the byte data of shortcut files, you can implement functionality to run with administrator privileges. This method requires deep understanding of the LNK file format.

$file="c:\temp\calc.lnk"
$bytes = [System.IO.File]::ReadAllBytes($file)
$bytes[0x15] = $bytes[0x15] -bor 0x20
[System.IO.File]::WriteAllBytes($file, $bytes)

This technique should be used with caution, and it's recommended to refer to Microsoft's official documentation for complete LNK file format specifications.

Copyright Notice: All rights in this article are reserved by the operators of DevGex. Reasonable sharing and citation are welcome; any reproduction, excerpting, or re-publication without prior permission is prohibited.