Managing Shortcut Files (Part 2)

by Jul 26, 2021

In the previous tip we created new shortcut files, and you have seen how the CreateShortcut() method provides methods to control almost any detail of a shortcut. Here’s the code again that creates a PowerShell shortcut on your Desktop:

$path = [Environment]::GetFolderPath('Desktop') | Join-Path -ChildPath 'myLink.lnk'
$scut = (New-Object -ComObject WScript.Shell).CreateShortcut($path)
$scut.TargetPath = 'powershell.exe'
$scut.IconLocation = 'powershell.exe,0'
$scut.Save()

That’s all to it: on your desktop there is now a new PowerShell link. Adjust the code above to create shortcuts to other applications and paths.


Twitter This Tip! ReTweet this Tip!