When you're writing scripts that are primarily meant for use in continuous integration or deployment environments, a lot of your inputs (maybe all of your inputs) are going to come from environment variables that are always set when you're running the scripts in production (but which rarely exist on your development box). There are a lot of different ways of handling this, but the one I find most elegant is to use PowerShell's dynamic parameter block.
Dynamic parameters in PowerShell have a couple of downsides (which, now that I think of it, we should really see about fixing, since PowerShell is open source).
- The first is that they are not easily discoverable. Even when you're in the conditions where the dynamic parameters will be emitted, they do not show up in either
Get-Command (nor even in
Get-Parameter, which does fetch dynamic parameters added by providers, but doesn't find the ones added by the command itself).
- The second is that they don't set variables in the function