Put a PowerShell Shortcut on Your Desktop

by Sep 1, 2011

Here is how you can create new shortcuts, such as a desktop shortcut to PowerShell:

$shell = New-Object -ComObject WScript.Shell    
$lnk = $shell.CreateShortcut("$([System.Environment]::GetFolderPath('Desktop'))\MyPS.lnk")
$lnk.TargetPath = (Get-Process -Id $pid).Path
$lnk.Save()    

Note that the shortcut created by this code will launch the very PowerShell host you ran to create the shortcut. So when you run it in PowerShell ISE, you will get a link to ISE, and when you run it in powershell.exe, the link will point to the PowerShell console.

Twitter This Tip!
ReTweet this Tip!