3

Currently, in my PowerShell scripts I am using [ValidateSet()] in my functions in order to limit the options for user input. Now I discovered the Enum as an alternative. I have read a couple of blogs about Enums vs ValidateSet, i.e. community.idera.com.

The advantages of ValidateSet() are supposed to be:

  1. Backwards compatibility
  2. Input validation
  3. ValidateSet() also provides IntelliSense

Advantages of Enums, i.e geekeefy and 4sysops:

  1. Input validation
  2. Avoid code repetition

Disadvantages of Enums:

  1. Not backwards compatible ( < PowerShell 5)

Now, I am wondering how to proceed. Should one continue using ValidateSet() as it has the same effect of user input validation, or are there other/better reasons why a PowerShell coder should prefer Enums over ValidateSet()?

Alex_P
  • 171

0 Answers0