Please feel free to provide feedback or file bugs here.

Dynamic param is silently ignored

Dynamic param is silently ignored, and no errors are thrown when CmdletBinding is not defined.


The following code should either run successfully, or throw an error:

Function Add-Control() {
DynamicParam {
$ParamAttribute = New-Object Parameter
$ParamAttribute.Mandatory = $true
$ParamAttribute.ParameterSetName = '__AllParameterSets'

$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]


$controlTypes = @("TextBox", "Label", "DataGrid")

$AttributeCollection.Add((New-Object ValidateSet($controlTypes)))

$RuntimeParam = New-Object System.Management.Automation.RuntimeDefinedParameter('Type', [string], $AttributeCollection)

$RuntimeParamDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary

$RuntimeParamDictionary.Add('Type', $RuntimeParam)

return $RuntimeParamDictionary

Process {
Write-Host ($PSBoundParameters['Type'])

Add-Control -Type "Test"
# $null

4 votes
Sign in
Password icon
Signed in as (Sign out)

We’ll send you updates on this idea

Božo Stojković shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

1 comment

Sign in
Password icon
Signed in as (Sign out)

Feedback and Knowledge Base