PowerShell: Get Object Type
Get Object's Type
To get a object type programatically, use .getType()
method.
"abc".getType().name # String "abc".getType().fullname # System.String
if you have a collection of objects, pipe it to foreach.
# see all types of a collection Get-ChildItem | ForEach-Object {$_.getType().fullname} # System.IO.DirectoryInfo or System.IO.FileInfo
Find the Types of Command Output, Interactively
- To find the object types of a command's output, pipe it to
Get-Member
. Get-Member
shows each distinct type once in its output, together with the type's members.
"abc" | Get-Member # System.String
dir | Get-Member # System.IO.DirectoryInfo, System.IO.FileInfo
Get-Date | Get-Member # System.DateTime
