Create a Shortcut with PowerShell


PowerShell is designed to do things in a simple way but every now and then you will find something that should be simple is a little difficult. One example of this is creating a shortcut. Below is an example function of how you do this. 


function New-ShortCut {
 param ($ShortCut,$Target,$Description,$Hotkey,$Icon,$WorkingDirectory)
 $Shell= New-Object -ComObject ("WScript.Shell")
 $ShortCut= $Shell.CreateShortcut("$ShortCut")
 $ShortCut.TargetPath= "$Target"
 $ShortCut.Description= "$Description"
 $ShortCut.Hotkey= "$Hotkey"
 $ShortCut.IconLocation= "$Icon"
 $ShortCut.WorkingDirectory= "$WorkingDirectory"
 $ShortCut.Save()
}

using the function




Comments