September 13th, 2014

PowerTip: Find Array Members with Get-Member in PowerShell

Doctor Scripto
Scripter

Summary: Learn to find members of an array with the Get-Member cmdlet in Windows PowerShell.

Hey, Scripting Guy! Question I have an array of numbers: 1,2,3,4,5 that I assigned to variable $a. When I pipe it to Get-Member: $a | gm,
           all I see are members for int32. How can I find the members of an array by using Get-Member?

Hey, Scripting Guy! Answer There are two ways to do this:

1. Use the uniary operator ( ) in front of the array prior to piping it to Get-Member:

PS C:\> $a = 1,2,3,4,5

PS C:\> ,$a | get-member

2. Use the –InputObject parameter with Get-Member:

Get-Member -InputObject $a

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

0 comments

Discussion are closed.