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 the Types of Command Output

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

examples:

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

Get the Type of an Object

List Properties of a Given Object Type

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

List Methods of a Given Object Type

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

Show Property Values of a Object

Show all properties and their values of a object

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

PowerShell: Value Types


PowerShell in Depth

Path

Pipe

Comment

Value Types

String

Variable

Boolean

Conditional

Data Structure

Loop and Iteration

Input/Output

Function

Profile and Script

Script Examples

Misc