Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get member list for an array object?

Tags:

powershell

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
   ...
like image 717
lit Avatar asked Oct 27 '25 08:10

lit


1 Answers

Get-Member -InputObject $a

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

like image 107
G42 Avatar answered Oct 29 '25 05:10

G42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!