Skip to content

Everything you need to know about Get-Member in PowerShell

Jordan Hammond fun headshot
Jordan Hammond|Updated January 5, 2021
Get-Member
Get-Member

My IT background contains no programming at all. I never even really wrote Batch scripts. I bring that up because I started learning PowerShell, and upon reading that it was object-oriented, my response was "neat." Not the appropriate response, which should have been "EVERYTHING IN MY LIFE IS WAY BETTER NOW!!"

Get-Member is a command that will let you know all you could ever want to know about the data you are collecting. Being object-oriented means you are not just getting a wall of text back, but  structured data. Let's take a quick look at an example using Get-Member.

pasted image 0

This object doesn't just contain the data but also has a list of methods that you can run against it. PowerShell will occasionally even throw in some script properties, which is the data with some extra PowerShell run against it. There is an excellent example of this in Get-Process. TotalProcessorTime is a timespan, which is not precisely how you might like that data. You can use the CPU scriptproperty, however, and it will break it down for you in total seconds. It is a built-in option to have usable information.

Finding your data type

Get-Member will also let you know what your data type is. In our example, you can see that it is a system.diagnostics.process. A quick look at Stop-Process and we can see that it accepts that data type as an InputObject.

unnamed

I know it seems obvious that something grabbed with Get-Process would work with Stop-Process. Knowing your data type becomes more important as we build our own functions. Let's take a quick look at a quick function.

Why knowing data type is important

Let's take a quick look at a quick function.

Function NoValue-Function { [cmdletbinding()] Param ( [parameter(ValueFromPipeline=$true)] [System.Diagnostics.Process[]]$name ) Begin { Write-Verbose "I have no new ideas." } Process { Write-Verbose "Please accept the pipeline" Stop-Process $name } }

First, please excuse my lack of proper Verb-Noun pairing. Second, reading through this, you can see all this is doing is stopping a process, but we are still able to pipe in the process object and have it accepted. You have started down the path to automating as much as your job away as you can, there is a good chance that you will be building out functions. Understanding as much as you can about the data you are grabbing will make your automation that much more powerful.

Wrapping up

If you are just getting started with PowerShell, this is one of the three commands that will give you all of the tools you need to accomplish what you are setting out to write.

  1. Get-Command: To help you find the commands you are looking for

  2. Get-Help: To help you understand how to use those commands

  3. Get-Member: To help you know what data you have, and how you can interact with it

That's it, what are you still here! Get out of here and start removing all the busy work from your life with the magic of PowerShell.

Jordan Hammond fun headshot
Jordan Hammond

Jordan had spent his life wondering why tasks he didn’t like to do had no options to complete themselves. Eventually he had to make that happen on his own. It turned out that he enjoyed making tasks complete themselves, and PDQ thought that is something he should talk about on the internet.

Related articles