Exploring the Power of Get-Member in PowerShell
Welcome back to Wahmans PowerShell blog! Today, we’re diving into an incredibly useful cmdlet that every PowerShell user, from beginner to pro, needs to know: Get-Member.
The official Microsoft documentation tells us that Get-Member
“gets the properties and methods of objects.” But what does that really mean in practice? In PowerShell, everything is an object, and Get-Member
is your magnifying glass into those objects, letting you examine what data and actions are available within them.
Understanding Get-Member
When you run a command in PowerShell, the result is not just some random text — it’s an object with structured data. Get-Member
helps you unlock that structure. You can see all available properties, methods, and even object types you’re dealing with. Why is this important? Because knowing what properties you can use or what methods you can call is key to writing powerful and effective scripts.
Example 1: Beginner – Discover Properties of a File
Get-Item "C:\example.txt" | Get-Member
This will show you all the properties and methods available on the FileInfo object returned by Get-Item
. You’ll see properties like Length
, CreationTime
, and methods such as Delete()
.
Example 2: Intermediate – Inspecting a Process Object
Get-Process | Get-Member
This command lists all properties and methods for each process returned by Get-Process
. Extremely useful when you want to know what details (e.g., CPU usage time, ID, name) you can access about running processes.
Example 3: Advanced – Filtering Members by Type
Get-Service | Get-Member -MemberType Property
This filters the output of Get-Member
to show only properties, excluding methods, aliases, etc. Combine this with -MemberType Method
or NoteProperty
to explore more specific details about an object.
Example 4: Power User – Exploring Custom Objects
$user = [PSCustomObject]@{
FirstName = "Anna"
LastName = "Wahman"
Age = 30
}
$user | Get-Member
This is an example of analyzing a custom object you’ve created. This is particularly useful in scripts that generate dynamic content and you need to introspect the structure before processing it further.
Final Thoughts
Get-Member
is one of the most essential tools in the PowerShell toolbox. Whenever you’re not sure what you’re working with, use Get-Member
to inspect the object and figure out what’s possible. It’s key for writing clean, smart scripts.
Happy scripting, and I will see you in the next post!
Leave a Reply