How to create a desktop shortcut using Powershell
Sometimes I find that simple tasks like creating a shortcut to an Application using a script are not straight forward. Looking for a simple way to place a shortcut on multiple users desktops using a Powershell script lead me to tools like mklink (which creates symbolic links, but not shortcuts).
surprisingly, I did not find a straight forward method to accomplish this.
However, I did find a way to create shortcuts using VBScript. Being more of a Powershell guy, I decided to convert this to a Powershell function in order to be able to reuse it as I see fit.
Using this function in your script is simple. Copy the function and place it as part of your script. Now all you need to do is call the function and supply the two parameters: $SourceLnk and $DestinationPath.
$SourceLnk is your link name, plus where your shortcut will be placed. For example: C:\users\MyUser\desktop
$DestinationPath is where this shortcut leads to. For example “C:\Program Files\Microsoft Office 15\root\office15\WINWORD.EXE”
function set-shortcut { param ( [string]$SourceLnk, [string]$DestinationPath ) $WshShell = New-Object -comObject WScript.Shell $Shortcut = $WshShell.CreateShortcut($SourceLnk) $Shortcut.TargetPath = $DestinationPath $Shortcut.Save() } set-shortcut "\\Where_This_Shortcut_is_Placed\Shortcut_Name.lnk" "\\Destination_Of_this_shortcut\app.exe"
Please feel free to ask and add comments.