Create Shortcuts with PowerShell

Copper Contributor

Hello, bonjour, bom dia, guten Tag,


As i write more and more unit tests for my functions i use, there are a few things making me wonder as my unittests fail and i first did not now why.
As a result i got 2 questions:


  • Is it wanted that it is possible to create a Shortcut without a name?


  • I am not able to set a hotkey at an url shortcut while it is possible via the GUI.
    Is it kinda bug or wanted?


 If the code is needed i could paste it.


Thanks in advance.


1 Reply

Hello @Michael Habermann,


Not sure if I understood correctly what were you trying to ask, but if you're trying to ask how to make a shortcut without a written name but with an extension you can try to use this, I tried this code and it was working for me. This is the example of making the shortcut for notepad:


$TargetFile = "$env:SystemRoot\System32\notepad.exe"
$FileName = ""
$ShortcutFile = "C:\Users\mbocak1\Desktop\$($FileName).lnk"
$WScriptShell = New-Object -ComObject WScript.Shell
$Shortcut = $WScriptShell.CreateShortcut($ShortcutFile)
$Shortcut.TargetPath = $TargetFile


Sorry if this is not what you were looking for, but if not, can you try explaining again?


Hope this will help!