How to create dynamic parameters

Suppose I set 3 parameters:a,b,c

`b` and `c` are dynamic parameters, shown and hidden according to the value of `a`

Suppose a = 1 b = 1;2 c=1;2;5;6;7

a = 2 c=6;7

PS >test {tab}
PS >test -a 1 -{tab}
b c
PS >test -a 2 -{tab}

PS >test -a 2 -c {tab}
6  7

Hi There,

Go through the script below on Dynamic Parameters from the GitHub and start building up on your own, and please let us know if you stuck any where…

Also there is another feature called Argument Completer, that could also be helpful to you, please refer to my blog post below…

Thank you.

The script does not support multiple parametersetname


I still don’t understand how to display dynamic parameters


This is a sample script to show you how it works and better understanding of the concept, it may not be the exact fit for your requirement, you need to modify it according to your requirements, and if you stuck anywhere then we are happy to help you.

I request you to please go through some online help on advanced functions and parameters for better understanding of the concept.

Thank you.

Using DynamicParam only I don’t know what to do

Test -a -b a
B -C
D -B

function test {
function ParamDictionary{
begin{$ParamDictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary}
$AttributeCollection=New-Object System.Collections.ObjectModel.Collection[System.Attribute]
$Attributes=New-Object System.Management.Automation.ParameterAttribute
if ($.Argument){
$AttributeCollection.Add((New-Object System.Management.Automation.ArgumentCompleterAttribute($
$RuntimeDefinedParameter=New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($.name,$.type,$AttributeCollection)

{param ( $commandName,

$possibleValues = @{
b = @(‘graphs’,‘boot’,‘reboot’,‘shutdown’,‘Destroy’,‘info’,‘status’,‘list-os’,‘list’,“reinstall”,“create”,“resize”,“reset-password”)
a = @(‘hypervisors’,‘boot’,‘graphs’,‘info’,‘reboot’,‘shutdown’,‘status’)
if ($fakeBoundParameters.ContainsKey(‘b’))
$possibleValues[‘b’] | Where-Object {
$_ -like “$wordToComplete*”
elseif ($fakeBoundParameters.ContainsKey(‘a’))
$possibleValues[‘a’] | Where-Object {
$_ -like “$wordToComplete*”
-eq ‘c’){$object+=@{Argument=$Argument}}

I can’t find a valid method

Test -a -b -c a
B -d
C -e
[pre]DynamicParam { $notid=@('list','list-os','create','hypervisors') if ($notid -notcontains $Name){ $Attributes = New-Object System.Management.Automation.ParameterAttribute $Attributes.Mandatory = $false $Attributes.ParameterSetName = '__AllParameterSets' $Attributes.ValueFromPipeline = $false $Attributes.ValueFromPipelineByPropertyName = $false

$AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
#$AttributeCollection.Add((New-Object System.Management.Automation.ValidateSetAttribute(’’)))

$ParamDictionary = New-Object -TypeName System.Management.Automation.RuntimeDefinedParameterDictionary
$ParamDictionary.Add($dname,(New-Object -TypeName System.Management.Automation.RuntimeDefinedParameter($dname,[int32],$AttributeCollection)))

return $ParamDictionary


I see you’ve cross-posted here from another site that I responded to you on.

DynmaicParams is an advanced topic (not really something folks new to PowerShell, but coming from another language (and I am assuming here) should do as a first thing), and as noted, you really need to spend some time ramping up on it to fully understand them and as such, limit the confusion you’d encounter, have encountered thus far.

Otherwise, you are asking folks to write the code for you and your pseudo-code is really not complete enough to dig at what you are after, thus forcing folks to give you generic and pointer responses for you to read up on.

Again, as I said in my other response, that there are plenty of examples of this DynamicParam thing all over the web. For Example:


Dynamic Parameters in PowerShell

Function Get-Order {
         HelpMessage="How many cups would you like to purchase?"
         HelpMessage="What would you like to purchase?"
   Process {
      $order = @()
      for ($cup = 1; $cup -le $cups; $cup++) {
          $order += "$($cup): A cup of $($product)"


Your example is meaningless, so I have seen the webpage long ago。

I do n’t need you to write me an answer, you just need to provide the method,