Skip to content

CommandInvocationIntrinsics.InvokeScript bind arguments to $input instead of $args #4923

Closed

Description

@PetSerAl

This lines:

public Collection<PSObject> InvokeScript(string script, params object[] args)
{
    return InvokeScript(script, true, PipelineResultTypes.None, args);
}

Pass args parameter into input parameter of called function, thus mixing them up.

Steps to reproduce

$ExecutionContext.SessionState.InvokeCommand.InvokeScript('"`$args:($args); `$input:($input)"', 1, 2, 3)

Expected behavior

$args:(1 2 3); $input:()

Actual behavior

$args:(); $input:(1 2 3)

Environment data

Tested in v2.0 and v5.1.15063.608

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Sep 27, 2017
  2. SteveL-MSFT commented on Sep 30, 2017

    @SteveL-MSFT
    Member

    Good find! This looks like just a mistake in the code.

  3. lzybkr commented on Oct 3, 2017

    @lzybkr
    Contributor

    @PowerShell/powershell-committee - Adding Breaking-Change because it is. Were call sites reviewed to evaluate impact? On the surface, it feels low risk, but it's hard to evaluate without knowing where the api is actually used.

  4. iSazonov commented on Oct 4, 2017

    @iSazonov
    Collaborator

    Reopen to track previous question.

  5. SteveL-MSFT commented on Oct 4, 2017

    @SteveL-MSFT
    Member

    Jason Shirk (@lzybkr) in our code, most calls are using InvokeScript(script) and the rest don't call this specific overload. Unfortunately, InvokeScript is a pretty common method name so a search on GitHub returns many results, but most I looked at briefly on the first 4 pages aren't PowerShell related.

  6. lzybkr commented on Oct 4, 2017

    @lzybkr
    Contributor

    You need to add an extension when searching - much more useful results:

    https://github.com/search?utf8=%E2%9C%93&q=InvokeScript+extension%3Aps1&type=Code
    https://github.com/search?utf8=%E2%9C%93&q=InvokeScript+extension%3Apsm1&type=Code

    I see many calls to what I think is the same api (mostly in psm1 files), but the parameter in question is always $null. I only sampled the results though.

  7. SteveL-MSFT commented on Oct 4, 2017

    @SteveL-MSFT
    Member

    Jason Shirk (@lzybkr) As best I could tell based on your search results, the Reflection module uses InvokeScript() passing in input/args. From my basic test, it appears to work fine with the change. Are you ok to close this?

  8. lzybkr commented on Oct 5, 2017

    @lzybkr
    Contributor

    That module doesn't call the overload that was fixed, so it's not affected by the change.
    I'm fine with closing as long as the change is documented properly.

  9. iSazonov commented on Oct 5, 2017

    @iSazonov
    Collaborator

    Steve Lee (@SteveL-MSFT) Could you please add this in the PR #4963 description (it is very short) for future documentation?

  10. SteveL-MSFT commented on Oct 5, 2017

    @SteveL-MSFT
    Member

    Ilya (@iSazonov) I've already added the documentation needed label to the PR

  11. iSazonov commented on Oct 5, 2017

    @iSazonov
    Collaborator

    Yes, I see. I meant that the description very short - don't clear that we should document.

  12. SteveL-MSFT commented on Oct 5, 2017

    @SteveL-MSFT
    Member

    I think it's clear enough when my team goes through the documentation needed items later. args was being passed to the input parameter incorrectly.

  13. MartinGC94 commented on Aug 20, 2025

    @MartinGC94
    Contributor

    Just ran into this while making a PowerShell module that is supposed to work in 5.1 and 7+ (please start shipping 7 with Windows). The workaround I came up with was to just add this to the snippet I run: $FixedInput = if ($args.Count -ne 0) {$args} else {$input} this also has the positive side effect of enumerating $input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Breaking-Changebreaking change that may affect usersIssue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-FixedThe issue is fixed.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions