Search notes:

PowerShell: Objects

A fundamental concept in PowerShell is that of objects. Objects are assigned to variables and objects flow through a pipeline.
Under the hood, a PowerShell object is implemented as an instance of the .NET class System.Management.Automation.PSObject, see also PSObject.

An object is typed

Each object has a type that can be determined with $obj.GetType():
PS C:\Users\Rene> $curDir = get-item .
PS C:\Users\Rene> $curDir.GetType()

IsPublic IsSerial Name           BaseType
-------- -------- ----           --------
True     False    DirectoryInfo  System.IO.FileSystemInfo
PowerShell also allows to create COM objects. Such an object's type is System.__ComObject.
PS C:\Users\Rene> $comObj = new-object -comObject shell.application
PS C:\Users\Rene> $comObj.GetType()

IsPublic IsSerial Name           BaseType
-------- -------- ----           --------
True     False    __ComObject    System.MarshalByRefObject
Of course, $obj.GetType() also returns an object whose type is System.RuntimeType:
PS C:\Users\Rene> $typ = $curDir.GetType()
PS C:\Users\Rene> $typ.GetType().FullName
System.RuntimeType

Properties and methods

As is the case in most programming languages, an object exposes properties and methods.
The names, member types and definitions of these properties and methods can be seen by piping an object into get-member:
PS C:\Users\Rene> $curDir | get-member
In order to restrict the output to properties, the get-member option -memberType can be used:
PS C:\Users\Rene> $curDir | get-member -memberType properties

   TypeName: System.IO.DirectoryInfo
Name                MemberType     Definition
----                ----------     ----------
…
FullName            Property       string FullName {get;}
LastAccessTime      Property       datetime LastAccessTime {get;set;}
LastAccessTimeUtc   Property       datetime LastAccessTimeUtc {get;set;}
…
In order to see the properties' values, the object can be piped into select-object:
PS C:\Users\Rene> $curDir | select-object -property *
…
FullName            : C:\Users\Rene
…
LastAccessTime      : 10/12/2019 9:09:47 AM
LastAccessTimeUtc   : 10/12/2019 7:09:47 AM
…
The -property flag is not even required so that the command can be abbreviated with
PS C:\Users\Rene> $curDir | select-object *
PowerShell allows to add properties and methods (collectively referred to as members) to objects dynamically, at runtime, with the add-member cmdLet.

Intrinsic members

A PowerShell object has a few intrinsic members. The member type of these intrinsic members is memberSet (See the System.ManagementAutomation.PSMemberTypes enum), so, an intrinsic member is in actuality a set of other members.
psBase The original properties of the «underlying» .NET framework object
psAdapted Properties and methods that were added in the Extended Type System.
psExtended Properties and methods that were added in types.ps1xml or using add-member cmdLet
psObject The adapter that converts the base object to a psObject
psTypeNames List of objects that are used when the object is formatted. These objects are searched for in the Format.ps1xml file. Compare with $obj.psObject.typeNames
A PowerShell object's intrinsic members are displayed using the -force option of the get-member cmdLet.
Compare with the properties that are related to items.

PSStandardMembers

PSStandardMembers is a hidden MemberSet. Because it is hidden, it requires the -force option of get-member to be displayed (as is also the case to display intrinsic members).
PS C:\> $proc = get-process -id $pid
PS C:\> $proc | get-member -force PSStandardMembers

   TypeName: System.Diagnostics.Process

Name              MemberType Definition
----              ---------- ----------
PSStandardMembers MemberSet  PSStandardMembers {DefaultDisplayPropertySet}
PSStandardMembers is interesting because it it has a property set with the name DefaultDisplayPropertySet, this property set defines the object's properties that should be displayed when the object is rendered on the console and no view is defined.
In the case of the $proc (System.Diagnostics.Process) object, these properties can be queried like so:
PC C:\> $proc.PSStandardMembers.DefaultDisplayPropertySet.ReferencedPropertyNames
Id
Handles
CPU
SI
Name
It turns out, that exactly those properties are displayed in the following (admittedly simple) pipeline:
PS C:\> $proc | format-list

Id      : 2980
Handles : 695
CPU     : 4.953125
SI      : 1
Name    : powershell

See also

An object can be serialized (persisted) with the export-cliXML cmdLet and later be instantiated again with the import-cliXML cmdLet (see the command noun cliXML).
The select-object cmdLet
Object creation in PowerShell
Get an object's property value by a dynamic property name
It is not possible to use *.format.ps1xml files to customize how hash tables are displayed.
The psObject object

Index