I am currently trying to get a command that I know works in CLI to run through a PowerShell Ise script but it will not allow me to run it as it is picking up a part of the command as a parameter.
I tried to run the following command, but it brings up an error:
Start-Process ssh -o KexAlgorithms=diffie-hellman-group14-sha1 Username@IP
Start-Process : Parameter cannot be processed because the parameter name 'o' is ambiguous. Possible matches include: -OutVariable -OutBuffer.
At line:1 char:30
+ Start-Process ssh -o KexAlgorithms=diffie-hellman-group14- ...
+ ~~
+ CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameter,Microsoft.PowerShell.Commands.StartProcessCommand
What is supposed to happen is the cli should pop up and allow me to access a switch which as i have stated earlier works when I manually input it into Cli.
tl;dr
As Mathias notes, you must quote the list of arguments to pass through to
ssh:There are two problems with your approach:
Because
-ois unquoted,Start-Processinterprets it as one of its parameter names.Thus, pass-through arguments that happen to look like PowerShell parameters, must be quoted, e.g. - if passed individually (which isn't advisable; see next point) -
'-o'.As for the error you saw:
PowerShell's "elastic syntax" allows you to use parameter-name prefixes for brevity, so you don't have to type / tab-complete the full parameter name.
However, such a prefix must be unambiguous; if it isn't, PowerShell complains and lists the candidate parameter names, such as
-OutVariableand-OutBufferfor-oin this case. Thus, prefix-outvwould have avoided the ambiguity, for instance. Also note that some parameters have unambiguous short aliases, such as-ovfor-OutVariable.More fundamentally, trying to pass multiple pass-through arguments individually to
Start-Processcauses a syntax error:It is best to specify all pass-through arguments as a single, quoted string, using embedded double-quoting, if necessary.
Start-Processexpects pass-through arguments via a single argument, passed to its-ArgumentList(-Args) parameter, which is the 2nd positional parameter.,-separated), a long-standing bug makes the single-string approach preferable.