Dynamic parameters
Dynamic parameters allow a developer to define the behavior of parameters when a function or script is run, rather than hardcoding that behavior in advance in a param
block.
Dynamic parameters can be used to overcome some of the limitations inherent in a param
block. For example, it is possible to change the parameters presented by a command based on the value of another parameter. It is also possible to dynamically write validation, such as dynamically assigning a value for the ValidateSet
attribute.
Dynamic parameters remain unpopular in the PowerShell community. They are relatively complex; that is, they are hard to define and difficult to troubleshoot as they tend to silently fail rather than raising an error.
Dynamic parameters have a named block: dynamicparam
. If you use dynamicparam
in a script or function, the implicit default blocks for a script or function cannot be used; all code must be contained within an explicitly named...