Skip to content

Using -Args with -Command does not work as documented #15410

@ghost

Description

The powershell command line docs suggest that the "-Command" option may be used with the "-args" option to pass extra arguments to a script block. However, this does not work as described.

Recommend updating the command line documentation to document the actual behavior of -Command, which does not support an -args option.

Usage: pwsh[.exe] [-Login] [[-File] <filePath> [args]]
                  [-Command { - | <script-block> [-args <arg-array>]
                                | <string> [<CommandParameters>] } ]

Steps to reproduce

powershell.exe -Command "{ echo $args[1] }" -args one two three

Expected behavior

print two

Actual behavior

error:

aaronla@aaronla-r:scratch$ dotnet pwsh -command "{ echo $args[1] }" -args one two three
ParserError:
Line |
   1 |  { echo $args[1] } -args one two three
     |                    ~~~~~
     | Unexpected token '-args' in expression or statement.

Environment data

aaronla@aaronla-r:PowerApps-CoreServices$ dotnet pwsh -command echo $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions