4

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?!?!?!?!

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.