PowerShell: Object Type, Properties, Methods
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.
- A command may output multiple objects.
- Each object has a type.
- The number of objects and type depends on the command parameter. For example,
dir -name
may return many objects but all of typeSystem.String
, butdir
may return many objects, some of typeSystem.IO.FileInfo
, some of typeSystem.IO.DirectoryInfo
.

help dir
, showing types of its input and output.

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.
gm
is alias ofGet-Member
examples:
"abc" | gm # System.String

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"

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

List Methods of a Given Object Type
dir -file | gm -MemberType Method

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 *
select
is alias ofSelect-Object
