Using PSTypeName

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 types.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.129.100