Commandlet with Parameter accepting ByPropertyName works for one parameter but not for other parameter

Viewed 13

Get-Command Accepts both Module and Name using ByPropertyName

help Get-Command -Parameter * 
-Module <System.String[]>
    Position?                    named
    Accept pipeline input?       True (ByPropertyName)

-Name <System.String[]>
    Position?                    0
    Accept pipeline input?       True (ByPropertyName, ByValue)

However

[PSCustomObject]@{Name = 'dir'} | Get-command    /*This Works*/ 

but

[PSCustomObject]@{Module = 'Microsoft.PowerShell.Archive'} | Get-command    /*This is NOT Working*/

enter image description here

1 Answers

The byvalue of name screws it up because of its higher precedence over the pipe. Here's a workaround, * for the name:

[pscustomobject]@{module = 'Microsoft.PowerShell.Archive'} | get-command -name *

CommandType     Name                        Version    Source
-----------     ----                        -------    ------
Function        Compress-Archive            1.2.5      Microsoft.PowerShell.Archive
Function        Expand-Archive              1.2.5      Microsoft.PowerShell.Archive

Even this way name is still required.

'Microsoft.PowerShell.Archive' | get-command -module { $_ } -name *
Related