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
}
}