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:
- Backwards compatibility
- Input validation
- ValidateSet() also provides IntelliSense
Advantages of Enums, i.e geekeefy and 4sysops:
- Input validation
- Avoid code repetition
Disadvantages of Enums:
- 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()
?