The Get-Member cmdlet is arguably the most useful cmdlet in PowerShell and often goes unnoticed by new PowerShell users. You can think of Get-Member as your detective's magnifying glass. The cmdlet allows you to learn about an object's properties and methods that you can call.
When you use Get-Member on a collection it will return the properties and methods about each Type within the collection. Below are the most commonly used switches on the cmdlet to take note of:
-Static: Return only static methods and properties.
-Name: Return only properties that match the provided name which can contain wild cards.
-MemberType: Commonly used with the value "Property" or "Method" to return only those members.
The following example shows how to get the members of a system event log message:
#
# Grab the first error record
# in the system event log.
#
$event = Get-EventLog -LogName System -EntryType error | select -First 1
#
# List all Members of the "EventLogEntry" object
#
$event | Get-Member
#
# List only Properties
#
$event | Get-Member -MemberType Property
#
# List only Methods
#
$event | Get-Member -MemberType Method
#
# Write Details about the log
#
Write-Host "Message: $($event.Message)"
Write-Host "Time: $($event.TimeGenerated)"
Write-Host "Type: $($event.EntryType)"
Message: The device, \Device\Ide\iaStor0, did not respond within the timeout period.
Time: 10/11/2013 21:34:20
Type: Error
The Get-Member cmdlet has an alias "gm" which you can use to save on typing.