You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Passing a script block to an external utility should only trigger Base64 encoding if the target is powershell -command #4973
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or more
Currently, any script block you pass to an external utility from within PowerShell translates translation of the script block into -encodedCommand <base64-encoded-script-block-string> -inputFormat xml -outputFormat text (you can override the -inputFormat and -outputFormat values by passing them explicitly, however), even though that only makes sense when invoking (another instance of) PowerShell.
PetSerAl has noted that it may be non-trivial to robustly detect when PowerShell is being called and that passing a script block to something other than PowerShell is generally not useful, but the current behavior is surprising and should at least be documented.
An easy improvement would be to restrict the implicit Base64-encoding to commands where -Command (or an unambiguous prefix) precedes the script block.
As for what should happen when it is not PowerShell that is targeted: arguably, a script block should be stringified and the result passed as an argument (e.g., { "hi" } -> "hi").
hi
"hi" # surrounded by a space on either side - the result of { "hi" }.ToString()
Actual behavior
hi
-encodedCommand IAAiAGgAaQAiACAA -inputFormat xml -outputFormat text
Environment data
PowerShell Core v6.0.0-beta.7 on macOS 10.12.6
PowerShell Core v6.0.0-beta.7 on Ubuntu 16.04.3 LTS
PowerShell Core v6.0.0-beta.7 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
Windows PowerShell v5.1.15063.502 on Microsoft Windows 10 Pro (64-bit; v10.0.15063)
I'd prefer having this just throw an error "Cannot pass a script block to a native application", at least in strict mode. The current behaviour looks rather strange if I forget to use quotation marks or --%:
PS C:\[REDACTED]\master> git rev-parse 1.15.4^{commit}
fatal: ambiguous argument 'YwBvAG0AbQBpAHQA': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
459878e67afb7ff3171072f4004037dbbc65aff3
-encodedCommand
YwBvAG0AbQBpAHQA
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.
Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-No ActivityIssue has had no activity for 6 months or more
Activity
PetSerAl commentedon Oct 2, 2017
Nitpicking, but it not always
-inputFormat xml -outputFormat text:mklement0 commentedon Oct 2, 2017
Thanks, PetSerAl - I've updated the original post to clarify that you can override
-inputFormatand-outputFormat.KalleOlaviNiemitalo commentedon Sep 29, 2023
I'd prefer having this just throw an error "Cannot pass a script block to a native application", at least in strict mode. The current behaviour looks rather strange if I forget to use quotation marks or
--%:microsoft-github-policy-service commentedon Mar 27, 2024
This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.
Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.