Short and sweet, I make shortcuts in PS, until the Target Path has a place in it, the shortcut works fine. As soon as Target has a place in it, the target shortcut is wrapped in double quotes and, as such, does not work ... Below is the non-working code. If you were to remove the space, that would be correct (well, except that it does not point to the EXE at that point). Basically, this will not wrap the target in quotation marks.
$shell = New-Object -ComObject WScript.Shell $shortcutX = $shell.CreateShortcut("C:\Short.lnk") $shortcutX.TargetPath = "C:\apps\application --switch" $shortcutX.Save()
TL DR:
Works.
$ shortcutX.TargetPath = "C: \ apps \ application"
Does not work!
$ shortcutX.TargetPath = "C: \ apps \ application -switch"
Why?!?!?!?!
source share