Skip to content

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

Closed

Description

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

Activity

  1. added
    Issue-Question
    on Oct 5, 2019
  2. added
    Hacktoberfest
    Issue-Bug
    and removed
    Issue-Question
    on Oct 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    HacktoberfestIssue-BugResolution-FixedWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions