Validating PowerShell Input Using Parameter Validation Attributes

PowerShell provides ways to validate acceptable parameter input for a function or a script. If you have taken an introductory computer science or programming course, you have learned first-hand about the importance of validating the values of parameters passed into your script, function, or program. You were taught that your program should nicely tell the user what was wrong and how to fix the problem. You may have ended up writing thousands of lines of code to cover every possible scenario where the user could mess up the input. Perhaps, you wrote one line of code that tells the user the input does not match the desired input. Huh? Sometimes it would almost be better to throw an error! PowerShell parameter validation attributes define what is acceptable for parameter input without needing to write massive amounts of code to handle it.

Read More