Reusable ValidateSets in PowerShell
When you’re creating scripts, in some cases, you may want to limit what values a consumer is allowed to provide for a specific parameter. In PowerShell a regular way to do that is with ValidateSet. ValidateSet is an attribute that you can define on a parameter together with a set of values that are allowed to be provided for the parameter. For example, let’s say you want to only allow to specify Development, Staging or Production as a value for the $DeploymentEnvironment parameter in your PowerShell script, with help of ValidateSet. It can look something like this: ...