Create a shortcut from PowerShell
To create a shortcut in PowerShell, the WScript.Shell COM object has a simple method (with additional properties not shown), which makes creating shortcuts programmatically simple. Below are a couple of examples, New-FavoriteShortcut will create a shortcut on the left pane of the File Explorer, for quick access to folders, applications and documents.
function New-Shortcut($TargetPath, $ShortcutPath) { $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut($ShortcutPath) $Shortcut.TargetPath = $TargetPath $Shortcut.Save() } function New-FavoriteShortcut($TargetPath, $DisplayName) { $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut("$env:USERPROFILE\Links\$DisplayName.lnk") $Shortcut.TargetPath = $TargetPath $Shortcut.Save() } |
August 17, 2013