public/Add-DynamicParameter.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

function Add-DynamicParameter() {
    Param(
        [Parameter(ValueFromPipeline = $True, ValueFromPipelineByPropertyName = $True)]
        [System.Management.Automation.RuntimeDefinedParameterDictionary] $Dictionary,

        [Parameter(Position = 0, ValueFromPipelineByPropertyName)]
        [System.Management.Automation.RuntimeDefinedParameter] $Parameter,

        [Switch] $PassThru 
    )

    if($PassThru.ToBool()) {
        $Dictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        [void]$Dictionary.Add($Parameter.Name, $Parameter);
        return $Dictionary;
    }

    [void]$Dictionary.Add($Parameter.Name, $Parameter);
}