Categories

#PSTip Getting information about a collection object, not its elements

You have a collection of values in a variable. When you pipe the variable to the Get-Member cmdlet you get the type and members of each item in that collection. PowerShell unrolls the collection and sends each item through the pipeline, one at a time, to the Get-Member cmdlet.

Most of the time that’s the desired output. However, there are cases where you’ll need to get the members of the collection itself. To do so, you can choose one of three approaches. Call the GetType method on a variable:

Like this:

About the author: Shay Levy

Shay Levy is a Co-founder and editor of the PowerShell Magazine. He is a multiple-year recipient of the Microsoft MVP award, and a Microsoft Certified Trainer (MCT). Shay often covers PowerShell related topics on his blog and you can also follow him on Twitter at @ShayLevy