I don't know any native cmdlet in powershell, but you can use the com object instead:
$WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$Home\Desktop\ColorPix.lnk") $Shortcut.TargetPath = "C:\Program Files (x86)\ColorPix\ColorPix.exe" $Shortcut.Save()
you can create powershell script file save as set-shortcut.ps1 in $ pwd
param ( [string]$SourceExe, [string]$DestinationPath ) $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut($DestinationPath) $Shortcut.TargetPath = $SourceExe $Shortcut.Save()
and name it as follows
Set-ShortCut "C:\Program Files (x86)\ColorPix\ColorPix.exe" "$Home\Desktop\ColorPix.lnk"
If you want to pass arguments to the target exe, this can be done with:
'Set the additional parameters for the shortcut $Shortcut.Arguments = "/argument=value"
to $ Shortcut.Save ().
For convenience, a modified version of set-shortcut.ps1 is provided here. It takes arguments as its second parameter.
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()
CB. Mar 14 '12 at 12:23 2012-03-14 12:23
source share