X Tutup
Skip to content

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

@mklement0

Description

@mklement0

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    HacktoberfestPotential candidate to participate in HacktoberfestIssue-BugIssue has been identified as a bug in the productResolution-FixedThe issue is fixed.WG-Cmdlets-Managementcmdlets in the Microsoft.PowerShell.Management module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup