PDQ.com mobilePDQ.com desktop

Get-Member in PowerShell

Jordan HammondJordan Hammond

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.

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.

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 {
Param (
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.

This is Where the Conclusion Goes

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.

Don't miss the next post!

Using PowerShell to Install Printers

When installing printers, we will need to do the four things; Add Driver to the Store, Install the Driver, Create Printer Port, and Install the Printer