PowerShell Essentials: Get-Member

by Apr 23, 2009

Get-Member is the third important basic PowerShell cmdlet as it gives you a documentation of what a command returns. It lists all of the object and property members. By default, you get everything:

Dir | Get-Member

Note how Get-Member analyzes the returned objects and returns two sets of data, one for the FileInfo and one for DirectoryInfo, at least if your folder contains both files and folders. You can use compare-object if you'd like to find out the differences between both object types:

$result = dir | gm
Compare-Object $result[0] $result[1] -property Name

Often, Get-Member provides a lot of information so it is a smart idea to limit it. For example, if you'd just like to find out what properties are available related to "time", try this:

dir | Get-Member *time* -memberType *Property