Chapter 13. Using and “abusing” dynamic parameters
In our lives we make choices all the time; some choices are obligatory, but sometimes they’re optional. Imagine you’re buying a bike. You need to customize it, and although some choices are “static,” such as selecting the frame or the wheels, some aren’t. For example, you’d consider stabilizers only if you were looking for a bike for a small child. At a bike shop a salesperson probably wouldn’t start a conversation about your purchase of a new bike with the question: “Which stabilizers do you prefer: ones with Spiderman or ones with Lightning McQueen?” But if you mention that you’re looking for a bike for your little son, these questions would seem natural. Dynamic parameters are additional options that only make sense in your current context and only then will you have a chance to use them.
Version 1 of the PowerShell scripting language already was powerful and flexible and with each new version it improves. PowerShell almost always uses some language elements in production scripts, such as parameter validation, comment-based help, and pipeline binding. But one rarely used feature (mainly because of complexity of application, limitations it brings to the table, and relatively small number of use cases) is the dynamic parameter. If you’ve ever been in a situation where you needed additional control over code, the dynamic parameter feature may be the solution for you.