September 25, 2021


A blog for USEFUL-IT information

PS : DynamicParam

How to use on DynamicParam in a function based upon input from a parameter

Cmdlet Dynamic Parameters

Cmdlets can define parameters that are available to the user under special conditions, such as when the argument of another parameter is a specific value. These parameters are added at runtime and are referred to as dynamic parameters because they are added only when they are needed. For example, you can design a cmdlet that adds several parameters only when a specific switch parameter is specified.

Get more info about these DynamicParam :

function get-info {

    [ValidateSet('A', 'B')]
    [string] $Target

DynamicParam {
        # Ensure $Target is defined
        try { [void]$Target }
        catch { $Target = [string]::Empty }

        if ($Target -eq 'B') {
            $target += " si"
end {
        Write-Host $Target