Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoke-Command -Hostname / -SSHConnection should accept the script block as the (first) positional argument #10708

Closed
mklement0 opened this issue Oct 5, 2019 · 0 comments · Fixed by #10721

Comments

@mklement0
Copy link
Contributor

commented Oct 5, 2019

When using WinRM-based remoting, the -ScriptBlock argument can be passed positionally; e.g.:

Invoke-Command -ComputerName . { 'hi' } 
# Implied: Invoke-Command -ComputerName . -ScriptBlock { 'hi' } 

Currently, this doesn't work for the equivalent SSH-based remoting commands:

Steps to reproduce

This assumes that the local machine is set up for SSH-based remoting.

{ Invoke-Command -HostName . { 'hi' } } | Should -Not -Throw
{ Invoke-Command -SSHConnection @{ HostName = '.' }  { 'hi' } } | Should -Not -Throw

Expected behavior

Both tests should pass.

Actual behavior

Both tests fail as follows:

Expected no exception to be thrown, but an exception
"A positional parameter cannot be found that accepts argument ' 'hi' '." was thrown from line:1 char:3

That is, positional use of the -ScriptBlock parameter is not supported.

Environment data

PowerShell Core 7.0.0-preview.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.