Scripting Games

Using PowerShell Parameter Validation to Make Your Day Easier

Boe Prox
1 min read
Share:

A number of entries in the Winter Scripting Games use parameter validation, but some that I have seen may not be using it correctly or to its full potential.
Writing functions or scripts require a variety of parameters which have different requirements based on a number of items. It could require a collection, objects of a certain type or even a certain range of items that it should only accept.
The idea of parameter validation is that you can specify specific checks on a parameter that is being used on a function or script. If the value or collection that is passed to the parameter doesn’t meet the specified requirements, a terminating error is thrown and the execution of the code halts and gives you an error stating (usually readable) the reason for the halt. This is very powerful and allows you to have much tighter control over the input that is going into the function. You don’t want to have your script go crazy halfway into the code execution because the values sent to the parameter were completely off of the wall.
Click here to be redirected to the original post of this article on the author’s blog site where you can read the remainder of the article.

Related Articles

Mar 18, 2018

Iron Scripter Preludes and Main Event: Rules and Info

Information is now available at IronScripter.us for the at-Summit events, and participants are advised to refresh themselves on the Rules.
Participants attending Summit should begin choosing their faction and getting to know their teammates in the faction-specific channels of the DevOps-Summit Slack team (open only to attendees and alumni).
Participants hoping to participate remotely may wish to start choosing a faction and finding a way to get in touch with them. The Faction Discussion may be a good way to do that.