Get-Member

Understanding the Power of Get-Member in PowerShell

Welcome back to Wahmans PowerShell blog! Today we are diving into a powerful cmdlet you will use all the time as you navigate through the world of objects in PowerShell — Get-Member.

As described by Microsoft, Get-Member “gets the properties and methods of objects.” But what does that mean in practical terms? In PowerShell, everything is an object, and Get-Member is your tool to understand those objects. With it, you can explore what data (properties) and capabilities (methods) an object has — a vital step for both troubleshooting and development.

Basic Syntax

Get-Member

You typically use it by piping an object into Get-Member:

"some string" | Get-Member

Example 1: Inspecting a Simple String (Beginner)

Let’s start simple. What happens when you pass a string to Get-Member?

"Hello World" | Get-Member

This example shows you all the properties and methods of a string object in PowerShell. You’ll see things like Length (a property) or ToUpper() (a method). Use this early on to understand what you can do with objects.

Example 2: Exploring a File Object (Intermediate)

Working with files in PowerShell is common. Let’s inspect a file object:

Get-Item C:\Windows\notepad.exe | Get-Member

This will return details of all the properties like Name, Length, and methods like Delete() or MoveTo(). Knowing what’s available lets you automate file management much more effectively.

Example 3: Using -MemberType to Filter Results (Advanced)

You don’t always want all members. You can filter using the -MemberType parameter.

Get-Service | Get-Member -MemberType Property

This limits the output to just the properties of a service object — perfect when you’re scripting and only care about data, not methods.

Example 4: Exploring Custom Objects (Advanced)

What about objects you create yourself? Here’s how to examine them:

$person = [PSCustomObject]@{
    FirstName = "Jane"
    LastName  = "Doe"
    Age       = 30
}
$person | Get-Member

This reveals the structure of your custom object, helpful when designing scripts that work with structured data or APIs. It confirms that your properties are named correctly and accessible.

Conclusion

Get-Member is one of the most valuable tools in your PowerShell toolkit. Whether you’re just starting or writing complex scripts, understanding your objects is critical — and Get-Member is the key to that understanding.

Happy scripting, and I will see you in the next post! 🚀

Leave a Reply

Your email address will not be published. Required fields are marked *