4

Get-Member returns an object name and member list for each type of object it contains.

PS C:\src\t\getlast> $a = @(1,'now')
PS C:\src\t\getlast> $a | gm

   TypeName: System.Int32
   ...
   TypeName: System.String
   ...

Is there a way to get the object name and member list for the array object itself? Creating an array containing an array and a different type is the only way I have found to get a list of members for an array object.

PS C:\src\t\getlast> $a = @(@(1),'now')
PS C:\src\t\getlast> $a.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

PS C:\src\t\getlast> $a | gm

   TypeName: System.Object[]
   ...
   TypeName: System.String
   ...
2
  • 5
    The standard trick to prevent this unrolling behavior is to wrap it into its own array by preceding it with a comma: ,$a | gm will get the members only of $a itself. Commented Oct 24, 2018 at 13:49
  • 1
    See this article for some nice explanations about arrays. Commented Oct 24, 2018 at 13:52

1 Answer 1

6
Get-Member -InputObject $a

Essentially, feed Get-Member the whole object as using the pipeline pipes it element by element.

Sign up to request clarification or add additional context in comments.

Comments

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.