February 2019
Intermediate to advanced
626 pages
15h 51m
English
It is not uncommon in PowerShell to want to pass an object created in one command, as a PSObject (or PSCustomObject), to another. The PSTypeName attribute is able to test the type name assigned to a custom object. Type names are assigned by setting (or adding) a value to the hidden PSTypeName property. There are a number of ways to tag PSCustomObject with a type name. The simplest is to set a value for a PSTypeName property, shown as follows:
$object = [PSCustomObject]@{ Property = 'Value' PSTypeName = 'SomeTypeName'}
The PSTypeName property remains hidden, but Get-Member will now show the new type name:
PS> $object | Get-MemberTypeName: SomeTypeNameName MemberType Definition---- ---------- ----------Equals Method ...
Read now
Unlock full access