PowerShell: How to List All Object Properties


Often you may want to view all of an object’s properties in PowerShell.

The easiest way to do so is by using the Get-Member cmdlet as follows:

Get-ChildItem $my_file | Get-Member

This particular example will retrieve all properties for the file saved in the location specified by the $my_file variable.

Occasionally the Get-Member cmdlet will only return the essential properties of some object or only the properties that are not null.

To force PowerShell to show all properties for a given object, you can specify Format-List * as follows:

Get-ChildItem $my_file | Get-Member | Format-List *

The following example shows how to use each of these methods in practice.

Example: How to List All Object Properties in PowerShell

Suppose we have a file located at the following path:

  • c:\users\bobbi\nba_data.csv

We can use the Get-ChildItem cmdlet to retrieve some basic information about this file:

$my_folder = 'c:\users\bobbi\nba_data.csv'
Get-ChildItem $my_folder

The following screenshot shows how to use this syntax in practice:

Notice that this returns an object with four properties: Mode, LastWriteTime, Length and Name.

Suppose that we would like to return all properties for this object.

We can use the Get-Member cmdlet to do so:

Get-ChildItem $my_file | Get-Member

The following screenshot shows how to use this syntax in practice:

The screenshot only shows the first 17 properties of the object but a total of 50 properties are displayed in the console.

To force PowerShell to show all properties for this object we can use the following syntax:

Get-ChildItem $my_file | Get-Member | Format-List *

The following screenshot shows how to use this syntax in practice:

PowerShell list all object properties

This returns a total of 54 properties for the object.

If you’d simply like to view the number of properties for an object, you can use the Count method as follows:

(Get-ChildItem $my_file | Get-Member | Measure-Object).Count
(Get-ChildItem $my_file | Get-Member | Format-List * | Measure-Object).Count

The following screenshot shows how to use this syntax in practice:

PowerShell count object properties

Notice that the first method returns a total of 50 properties while using Format-List * allows us to see all 54 properties of the object.

Note: You can find the complete documentation for the Get-Member cmdlet in PowerShell here.

Related Tutorials

The following tutorials explain how to perform other common tasks in PowerShell:

PowerShell: How to Use Group-Object with Multiple Properties
PowerShell: How to Use Sort-Object with Multiple Properties
PowerShell: How to Use Where-Object in List

Leave a Reply