Skip to content

Get-Command doesn't properly recognize System.Management.Automation.CommandInfo (its own output type) as pipeline input #11017

Closed

Description

#10851 reported that feeding Get-Command output to itself via the pipeline - useful if you want to force loading of all modules in the context of reflection, for instance - doesn't work as expected.

#10929 tried to fix that, but fell short.

Steps to reproduce

function foo {}; set-alias foo foo

(gcm -all foo | gcm).Count | Should -Be 2

(gcm -all foo | gcm).ComandType | Should -Be Alias, Function

Expected behavior

The tests should succeed.

Actual behavior

The tests fail:

Expected 2, but got 278                   #  *all* commands are returned
Expected @('Alias', 'Function'), but got $null

Environment data

PowerShell Core 7.0.0-preview.5, with PR #10929 applied

Activity

  1. added
    Issue-Question
    on Nov 7, 2019
  2. SteveL-MSFT commented on Nov 8, 2019

    @SteveL-MSFT
    Member

    So what's happening is that the foo function doesn't have a Noun or Verb (they are empty strings), but it does have a Noun and Verb property, so when it's piped to gcm it binds to -Noun and -Verb, since they are empty string, gcm does a wildcard search thus returning everything. A simpler repro:

    function foo{}; gcm foo | gcm

    Adding a new parameterset to accept CommandInfo won't help as the default parameter set is Noun/Verb which will match any CommandInfo object.

    A possible fix would be if Noun and Verb are both empty, inspect the pipeline object further and use whatever is available to match: Name and CommandType

  3. vexx32 commented on Nov 8, 2019

    @vexx32
    Collaborator

    Given there is currently no pipeline parameter accepting this object as input in its complete form, would that information be available to Get-Command?

  4. SteveL-MSFT commented on Nov 8, 2019

    @SteveL-MSFT
    Member

    Rain Sallow (/u/ta11ow) (@vexx32) excellent point, it wouldn't as only Noun and Verb would be there. Hmmm, I guess the only way to fix this I can think of is a breaking change so that CommandInfo parameterset is default.

  5. mklement0 commented on Nov 8, 2019

    @mklement0
    ContributorAuthor

    Steve Lee (@SteveL-MSFT): It's fine to leave the default parameter set as-is - a specifically CommandInfo-typed parameter would still bind correctly.

  6. SteveL-MSFT commented on Nov 8, 2019

    @SteveL-MSFT
    Member

    Michael Klement (@mklement0) it would bind correctly if the default parameter set doesn't bind first which it will

  7. mklement0 commented on Nov 8, 2019

    @mklement0
    ContributorAuthor

    Steve Lee (@SteveL-MSFT)

    It doesn't necessarily bind first, but, as I just realized, it does if you combine it with a parameter not supported in a potential new CommandInfo-typed parameter set.

    So the choices are:

    • (a) change the default parameter set

    • (b) make the new parameter set support all other parameters (except -Name), even though some combinations don't make sense (such as -UseFuzzyMatching).

    I'm unclear on the ramifications of (a)

    (b) could be addressed by either warning about inapplicable arguments or throwing an error (there's already one instance of that in the existing code).

  8. SteveL-MSFT commented on Nov 8, 2019

    @SteveL-MSFT
    Member

    Changing the default parameter set makes the most sense to me, but also unclear how many will be impacted.

  9. iSazonov commented on Nov 9, 2019

    @iSazonov
    Collaborator

    We could add optional parameter -Name in the default parameter set.

  10. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  11. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  12. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

  13. added
    Resolution-No Activity
    on Nov 16, 2023
  14. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

  15. added
    WG-Cmdlets
    and removed on Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-QuestionResolution-No ActivityWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions