Question

Short and sweet, I am making shortcuts in PS, so long as the Target Path does not have a space in it the shortcut works fine. Once the Target has a space in it the Shortcut Target is wrapped in double quotes and as such doesn't work... Below is the non-working code. If you were to remove the space it would correctly (well except for the fact that it isn't pointing to the EXE at that point). Basically it wouldn't wrap the target in quotes.

$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"

Doesn't work!

$shortcutX.TargetPath = "C:\apps\application --switch"

Why?!?!?!?!

Was it helpful?

Solution

From MSDN:

This property is for the shortcut's target path only.

You can add arguments to the shortcut in the Argument's property.

$shortcutX.Arguments = "-- switch"

On my box (Windows 7 Pro), I can make shortcut with the path destination having spaces.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top