Contents

PowerShell Prowess: The 3 commands you need to know 👈

Next to the Get-Command and hte Get-Help cmdlets, there are 3 other cmdlets that are essential for any PowerShell user. In this blog post I will explain my view on why they are essential and provide hands-on examples on how to use them.

Unveiling Object Properties and Methods with Get-Member

The official documentation states: The Get-Member cmdlet gets the members, the properties and methods, of objects. Making it the Swiss army knife for exploring the properties and methods of any object in PowerShell and thus indispensable for any PowerShell user.

Why you need to know Get-Member:

  1. Object Exploration -> When working with PowerShell objects it’s crucial to understand the object you are dealing with. Get-Member helps to uncover the object’s properties, methods, and other characteristics.
  2. Discover Object Type -> Get-Member can be used to determine the type of an object. This is especially useful when working with pipelines, as different cmdlets return objects of varying types.

Get-Member Example

In this example the Get-MgUser cmdlet is used to retrieve a user from the Microsoft Graph. Note the result:

/posts/2023/powershell-prowess-the-3-commands-you-need-to-know/get-member-01.png
Get-MgUser cmdlet returns the bare minimal properties

Now note the Get-Member output:

/posts/2023/powershell-prowess-the-3-commands-you-need-to-know/get-member-02.png
By pipeing the command to Get-Member all properties, methods, and other characteristics are now visible and explorable

Note
Easily overlooked, but as mentioned the Get-Member cmdlet also returns the objects TypeName.

Tailoring Object Output with Select-Object

The official documentation states: Selects objects or object properties. The cherry picker for displaying and formatting specific properties of an objects. Making it an invaluable for formatting and refining data.

This is a versatile command that enables customization of the properties of an object’s output.

Why you need to know Select-Object:

  1. Data Shaping -> Tailoring object output to specific needs by including, excluding ordering and filtering properties. This is crucial for creating neat and organized objects.
  2. Efficient Scripting -> When working with complex objects, displaying all available properties with Select-Object -Property * helps by making output transparent and easier to work with.

Select-Object Example

The example is a continuation of the previous one. First all properties are listed. Then a selection is made of the preferred properties. Finally the selected properties for the last 3 objects are returned.

/posts/2023/powershell-prowess-the-3-commands-you-need-to-know/select-object-01.png
Listing all properties using the -Property * command
/posts/2023/powershell-prowess-the-3-commands-you-need-to-know/select-object-02.png
Selecting specific properties
/posts/2023/powershell-prowess-the-3-commands-you-need-to-know/select-object-03.png
Returning the selected properties from the last 3 objects

The Full Name(space) of a Data Type with [DataType].FullName

Outside of folder and file paths this method is a less known one and requires a bit more explanation. PowerShell uses a concept called Type Accelerators to make it easier to work with .NET types. A Type Accelerator is a shortcut for a .NET type. For example [int] is a shortcut for the .NET type System.Int32. While the intent of the type accelerators is to shorten the names of .NET types there are reasons to use the full name of a type. Such is the case when using the New-Object cmdlet to create an instance of a .NET type which can be retrieved by using the [DataType].FullName method. Another consideration for using the full name comes from the best practice to avoid aliases (PSAvoidUsingCmdletAliases), since the type accelerators are aliases for .NET types some PowerShell devs (like myself) prefer using the .NET types.

[DataType].FullName Example

To get a list of all available type accelerators use the following command:

/posts/2023/powershell-prowess-the-3-commands-you-need-to-know/full-name-01.png
List of all Type Accelerators
/posts/2023/powershell-prowess-the-3-commands-you-need-to-know/full-name-02.png
Example of the most common Type Accelerators full names

Wrapping up

That’s all folks! I hope you found the Get-Member, Select-Object and the DataType Accelerators .FullName commands as useful and need to know as I do. If you are interested in the reference material used to make this post, please visit the following links.

Get-Member

Select-Object

[DataType].FullName

As always, a big thanks for reading this post. If you liked it, don’t be shy and have a look at my other posts .