0

This works:

Get-Command $PSCommandPath | %{ $_.Parameters }

But this doesn't:

Get-Command $PSCommandPath | %{ $_.Parameters | %{ echo $_.Value } }

Why?

1
  • I am confused on what you are trying to accomplish? You want to pipe the results into another where statement? Commented Dec 26, 2013 at 14:33

1 Answer 1

3

The Parameters property is a hash table (dictionary):

Get-Command $PSCommandPath | %{ $_.Parameters.GetType() }


IsPublic IsSerial Name                                     BaseType                                                              
-------- -------- ----                                     --------                                                              
True     True     Dictionary`2                             System.Object                                                         

The Powershell pipeline will automatically "unroll" arrays and collections, but not hash tables. If you want to foreachthrough the indivudual elements, you have to enumerate them expliclitly using .getenumerator().

Get-Command $PSCommandPath | %{ $_.Parameters.GetEnumerator() | % {echo $_.Value } }
Sign up to request clarification or add additional context in comments.

4 Comments

Yea! almost there.. but this: echo $_.Value.ToString() emits: System.Management.Automation.ParameterMetadata instead of the parameter string value.. how can I output the parameter's text?
and ` %{ foreach($i in $_.Parameters.GetEnumerator()) { echo $i.Value.ToString() } }` gives the same: System.Management.Automation.ParameterMetadata
Define "the parameter's text".
ok, got it: Get-Command $PSCommandPath | %{ $_.Parameters.GetEnumerator() | % { (Get-Variable $_.Key).Value } }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.