How to convert PSCustomObject with additional props to a custom class
问题 Is there a neat way to convert a PSCustomObject to a custom class as a function parameter in PowerShell 5.1? The custom object contains additional properties. I'd like to be able to do something like this: class MyClass { [ValidateNotNullOrEmpty()][string]$PropA } $input = [pscustomobject]@{ PropA = 'propA'; AdditionalProp = 'additionalProp'; } function DuckTypingFtw { [CmdletBinding()] param( [Parameter(Mandatory = $True, Position = 0, ValueFromPipeline)] [MyClass] $myObj ) 'Success!' }