Reputation: 169
Simple wish for a Windows shortcut: I want to open a PowerShell window in a specific directory, and then have the shortcut enter and run a command.
This is how it looks right now when editing the "Target" of the shortcut:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command "cd 'C:\eARKIV\Programmer\Android ADB'" -Command 'test'
The directory change works, but I get the below error when trying to enter an input through the shortcut:
"Set-Location : A parameter cannot be found that matches parameter name 'Command'."
How can I circumvent this and get it to work? :(
Upvotes: 8
Views: 5840
Reputation: 439692
Only one -Command
argument is supported; everything after (the first) -Command
becomes part of the command to execute in the new session[1], as powershell -?
explains
.
To pass multiple commands, use ;
inside the "..."
string passed to the (one and only)
-Command
parameter:
... -NoExit -Command "cd 'C:\eARKIV\Programmer\Android ADB'; & 'test'"
Note that -Command
must be the last argument passed.[2]
[1] Therefore, -Command 'test'
accidentally became additional arguments passed to your cd
(Set-Location
) command inside the new PowerShell session, and that's what the error complained about - which also implies that the cd
command did not succeed in changing the current location (working directory)
[2] Technically, you may follow -Command
with multiple arguments, but they all become part of the code that PowerShell executes in the new session. For conceptual clarity and to avoid (more severe) escaping and quoting headaches, it is preferable to pass all of the commands as a single, "..."
-quoted string.
Upvotes: 10