Main | Contact | Blog | Documentation

PowerShell Framework

The project dedicated to empowering your PowerShell scripting.

ScriptTransformation

Back to utility

Synopsis

The ScriptTransformation Argument Transformation Attribute enables you to simply provide the conversion logic used in script.

Description

There are two things needed to make this work:

An example:

# Register the scriptblock
Register-PSFArgumentTransformationScriptblock -Name 'MyModule.Answer' -Scriptblock {
    if ('Answer' -eq $_) { 42 }
    # Can be as long as needed, only the first output object will be used
}

# Apply to function
function Get-Number {
    [CmdletBinding()]
    param (
        [PSFramework.Utility.ScriptTransformation('MyModule.Answer', [int])]
        [int]
        $Number
    )
    $Number
}

# Test
Get-Number -Number 23 # 23
Get-Number -Number '42' # 42
Get-Number -Number 'Answer' # 42
Get-Number -Number 'Foo' # Error

Notes

Back to utility