-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Summary of the new feature / enhancement
This is a follow-up on one specific aspect of #8816.
The irm ... | iex
pattern is well-known and widely used for installing software, similarly to curl ... | sh
on POSIX-like systems. We may not be happy about it, but it is widely used, and projects will use continue to use it in the future unless Invoke-Expression
is removed alltogether.
#8816 floated some alternative options, converging on extending Invoke-Command
. However, compatibility across all commonly used versions of PowerShell is vital for an installer script; a script that only works on some versions of PowerShell is not very useful as a one-liner, since now you have to give multiple one-liners and make the user choose based on the version of PowerShell they're using. This gives me a strong reason to believe that software vendors (including me) will NOT switch to any new backwards-imcompatible option to run downloaded scripts in one command.
One of the limitations of irm ... | iex
mentioned in #8816 was that there's no intuitive way to pass optional arguments to the installer script. Unlike some of the issues, I believe that this issue may be resolved in a backwards-compatible way by allowing Invoke-Expression
to receive additional arguments and passing them to the invoked script.
Users on older versions of PowerShell will still be able to use the iex "& {$(irm ...)} arg"
hack shown in the original issue, while users on new versions of PowerShell can pass arguments the way they would intuitively expect, the same way as with curl ... | sh
.
Proposed technical implementation details (optional)
Add a new -ArgumentList
parameter to Invoke-Expression
, with Parameter(ValueFromRemainingArguments = true)
. As a result, users should be able to do the following:
irm ... | iex arg -Flag1 -Flag2
If the script provides a param()
block, the arguments should be bound as if the script was invoked as a scriptblock with &
.