February 2019
Intermediate to advanced
626 pages
15h 51m
English
The PSTypeName attribute may also be used to tightly define the objects acceptable for a parameter that uses ValueFromPipeline:
function Get-InputObject { [CmdletBinding()] param ( [Parameter(ValueFromPipeline)] [PSTypeName('CustomTypeName')] $InputObject ) process { $InputObject.Name }}
This function would accept input from an object that declares the matching type name:
[PSCustomObject]@{ Name = 'Value' PSTypeName = 'CustomTypeName'} | Get-InputObject
A .NET type may also be assigned to the InputObject parameter in addition to PSTypeName. However, in this case, the type would have to be either Object or PSObject. This is effectively pointless as absolutely any object type in PowerShell will satisfy either of those parameter ...
Read now
Unlock full access