PowerShell: Object Type, Properties, Methods

By Xah Lee. Date: . Last updated: .

PowerShell commands input (parameter args) and output are all .NET objects. Each .NET object has a type, and members (“member” means properties and methods.). It's critical to understand this to master PowerShell.

PowerShell help dir 2021-05-25 ZY62f
help dir, showing types of its input and output.
Screenshot 2021-09-09 205739 zH7S7
help dir output, showing the types of paramater args.

Find a Object's Type: Get-Member

To find the object type(s) of a command's output, pipe it to Get-Member. For each object type, Get-Member shows it only once in its output.

examples:

"abc" | gm
# System.String
PowerShell get-member 2022-04-28
get-member
dir | gm
# System.IO.DirectoryInfo, System.IO.FileInfo
Get-Date | gm
# System.DateTime

Get Object Type programatically

To get a object type programatically, use .getType() method.

"abc".getType().ToString()
# "System.String"
PowerShell getType 2022-04-28
getType()

if you have potentially multiple objects, pipe it to foreach.

dir | ForEach-Object {$_.getType().ToString()}
# System.IO.DirectoryInfo or System.IO.FileInfo
Get-Date | ForEach-Object {$_.getType().ToString()}
# System.DateTime

List Properties of a Given Object Type

dir -file | gm -MemberType Properties
PowerShell list properties 2022-04-24
list properties

List Methods of a Given Object Type

dir -file | gm -MemberType Method
PowerShell list methods 2022-04-24
list methods

Show Property Values of a Object

Show all properties and their values of a output object

Get-Date | select -Property *
dir -file | select -First 1 | select -Property *
PowerShell list property values 2022-04-24
list property values

PowerShell

How-to

Advanced

Script Examples