concept Get - Member in category powershell

appears as: Get-Member, Get-Member
PowerShell in Practice

This is an excerpt from Manning's book PowerShell in Practice.

.NET objects may sound complicated, but we can discover which particular .NET object is being passed by using Get-Member, as shown in listing 1.2.

Listing 1.2. Using Get-Member to view the .NET type

The use of Get-Member shows that the Get-Process cmdlet is producing, or emitting, .NET objects of type System.Diagnostics.Process. This .NET type has a property called Handles. The Where-Object cmdlet performs a filtering operation based on the value of the Handles property of each .NET object. Any object that has a value greater than 500 for the Handles property is passed. All other objects are filtered out.

Get-Help and Get-Command provide information about PowerShell and PowerShell commands. We’re always dealing with objects in PowerShell. When we want to discover things about objects, we turn to Get-Member.

Get-Member is best described as the Swiss Army knife of PowerShell. It seems to be the one tool for which I’m always reaching. It would be worth reading the help file for Get-Member. Type Get-Help Get-Member to display it. Get-Member retrieves information about objects. PowerShell cmdlets return objects, so we can use Get-Member to view those objects.

Note that that only eight properties are shown for each process. If you’ve looked at processes in Task manager, you’ll know there are a lot more properties available. We use Get-Member to view them. Objects and properties are covered in more detail in the next chapter but for now think of them as a piece of information that helps describe the object (e.g., “red” is the value of the property color for a red balloon).

Typing Get-Process c* | Get-Member will return more information than can easily be displayed on a page, so I’ll leave that for you to try. We can use Get-Member to only display the property names as follows.

Listing 2.4. Using Get-Member to view object properties
Figure 3.4. Output of Get-Member on an Active Directory user object
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest