Get-Member (Alias: gm)
When working with PowerShell, it is crucial to understand the properties and methods of objects you are dealing with. One of the most useful cmdlets for this purpose is Get-Member. This cmdlet provides insights into the structure of objects, allowing users to interact effectively with them.
1. What is Get-Member, and Why is it Important?
Get-Member, and Why is it Important?Definition
Get-Member is a cmdlet in PowerShell that reveals the properties, methods, and events available on an object. Each object in PowerShell is based on a .NET class, and Get-Member allows users to inspect these objects to understand their capabilities.
Why Use Get-Member?
Get-Member?When working with unfamiliar objects,
Get-Memberhelps identify the available properties and methods.It enables users to discover how they can manipulate or retrieve data from an object.
It is useful when troubleshooting scripts, as it provides a clear view of what an object contains.
Example
Get-Process | Get-MemberThis command retrieves a list of running processes and pipes them into Get-Member. The output displays:
The type/class name (
System.Diagnostics.Process)The list of properties and methods available for process objects.

2. How Get-Member Works
Get-Member WorksBasic Functionality
Whenever an object is piped into Get-Member, it inspects the first object in the pipeline and returns:
The type or class name of the object.
The properties and methods available for that object.
Example: Examining a Registry Item
$x = Get-Item HKLM:\
$x | Get-MemberGet-Item HKLM:\retrieves an item from the registry.Piping
$xintoGet-Memberdisplays its available members.
This is useful when dealing with objects of unknown types.

3. Using Get-Member with Different Object Types
Get-Member with Different Object TypesInspecting a Collection vs. an Item Inside a Collection
When working with collections (arrays, lists, etc.), it is important to differentiate between inspecting an individual item and inspecting the collection itself.
Example 1: Inspecting the First Item in a Collection
$output = Get-ChildItem C:\
$output | Get-MemberThis command retrieves items from
C:\(files and directories).Piping
$outputintoGet-Membershows the members of the first item in the collection.
Example 2: Inspecting the Collection Itself
Get-Member -InputObject $outputUsing
-InputObject $outputinspects the array itself (System.Object[]), revealing members likeCount,Length, andSyncRoot.
Understanding How Get-Member Handles Mixed Object Types
Get-Member Handles Mixed Object TypesIf multiple object types are piped into Get-Member, it does not list the members of every single object instance. Instead, it groups objects by type and displays the members for each unique type.
Example: Mixed Object Types
Get-ChildItem | Get-MemberIf
Get-ChildItemreturns a mix of files and directories,Get-Memberwill display members separately forSystem.IO.FileInfoandSystem.IO.DirectoryInfo.
4. Alternative Ways to Use Get-Member
Get-MemberUsing the -MemberType Parameter
-MemberType ParameterTo filter results, use the -MemberType parameter.
Get-Process | Get-Member -MemberType Property
This command displays only the properties of
System.Diagnostics.Process.
Get-Process | Get-Member -MemberType MethodThis command displays only the methods of
System.Diagnostics.Process.
Using the -Name Parameter to Search for a Specific Member
-Name Parameter to Search for a Specific MemberGet-Process | Get-Member -Name HandleCountThis checks if
HandleCountexists as a property or method.
Inspecting Static Members
[System.Math] | Get-Member -StaticThis displays static methods and properties of
System.Math.
Last updated
