powershell - How to add a SwitchParameter to an attribute collection? -
i have attribute collection defined so:
$attributecollection = new-object system.collections.objectmodel.collection[system.attribute]
while able add attributes , validateset options unable add switchparameter collection.
$switchparameter = new-object system.management.automation.switchparameter $attributecollection.add($switchparameter)
when run above following error:
cannot find overload "add" , argument count: "1".
since attribute collection takes parameter of type system.attribute
guess there must different way of adding switchparameter, not sure how.
you not have use additional attributes make parameter switch parameter. declare it's type system.management.automation.switchparameter
or switch
.
function f{ [cmdletbinding()] param( [string[]]$names ) dynamicparam{ $dynamicparams=new-object system.management.automation.runtimedefinedparameterdictionary foreach($name in $names){ $attributes=@( new-object parameter -property @{parametersetname="set_$name"} ) $param=new-object system.management.automation.runtimedefinedparameter $name,switch,$attributes $dynamicparams.add($name,$param) } $dynamicparams } }
Comments
Post a Comment