Using the RuntimeDefinedParameterDictionary

RuntimeDefinedParameterDictionary is the expected output from the dynamicparam block. The dictionary must contain all of the dynamic parameters a function is expected to present.

The following example creates a dictionary and adds a single parameter:

using namespace System.Management.Automation

function Test-DynamicParam {
[CmdletBinding()]
param ( )

dynamicparam {
$paramDictionary = [RuntimeDefinedParameterDictionary]::new()

$parameter = [RuntimeDefinedParameter]::new('Action', [String], [Attribute[]]@(
[Parameter]@{ Mandatory = $true; Position = 1 }

[ValidateSet]::new('Start', 'Stop', 'Create', 'Delete')
)
)
$paramDictionary.Add($parameter.Name, $parameter)

$paramDictionary
}
}
..................Content has been hidden....................

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