Powershell

How to get properties of an object in PowerShell?

PowerShell is among the most popular and frequently used scripting languages. Do you know what makes PowerShell so popular? Objects! It’s an object that makes PowerShell different from traditional Shells such as command prompt and Bash. PowerShell is not just about the scripts; instead, PowerShell is an object-oriented scripting language, consists of a command-line shell, and is based on the .Net framework. The traditional shells are text/string centric, however, in PowerShell, everything revolves around the objects.

Every object has some properties that store information about the objects. Now You must be wondering how to get the object’s properties in PowerShell? No worries! This post is going to assist you in this regard.

This write-up will explore how to get the properties of an object in PowerShell and in this regard it will present a detailed understanding of the following concepts:

  • Object and Properties in PowerShell
  • What is Get-Member and how to use it in PowerShell?

So, let’s get started!

Object and Properties in PowerShell

Objects are one of the aspects of PowerShell that make it special as compared to other shell environments such as bash, command prompt, etc. Objects are simply a representation of something or we can say that objects are entities that can have various attributes. In PowerShell, objects are used to return, store, and manipulate the information instead of strings/text. In PowerShell, properties are the attributes of an object or we can say that the properties are the characteristics of an item.

What is Get-Member and how to use it in PowerShell?

In PowerShell, the Get-Member cmdlet(command-let) is used to get the object properties. PowerShell pipes can be used with the Get-Member property to pipe the output of the specified cmdlet into the Get-Member.

Consider the below-given examples for a profound understanding of how to get the properties of an object in PowerShell:

How to get the properties of the “Process” in PowerShell?
The below snippet will guide you on how to get the properties of the Process object:

Get-Process | Get-Member

The Get-Process cmdlet will get all the processes on a local/remote computer and will assign the output to the Get-Member cmdlet. The Get-Member cmdlet will show us the object name, its properties, alias properties, methods, and scripting properties:

The above snippet shows that the Get-Member cmdlet shows us the name of the object type and a complete list of its members.

How to get the properties of the “FileInfo” in PowerShell?
The GetChild-item cmdlet can be used to get the FileInfo object in PowerShell as shown in the below snippet:

Get-ChildItem | Get-Member

In the above snippet we utilized the Get-ChildItem cmdlet to get the FileInfo object and we passed the output of the Get-ChildItem to the Get-Member cmdlet using pipeline operator:

This is how we can get the properties of an object in PowerShell.

Conclusion

To get the object properties, the Get-member cmdlet is used in PowerShell. Specify a cmdlet, use the pipeline operator, and then type the Get-Member cmdlet to see all of the properties available from the specified command. This write-up explained how to get the properties of an object in PowerShell using the Get-Member cmdlet. For a profound understanding of the concept, this post presented a couple of examples.

About the author

Anees Asghar

I am a self-motivated IT professional having more than one year of industry experience in technical writing. I am passionate about writing on the topics related to web development.