PowerShell for Windows Admins

Jun 8 2014   7:32AM GMT

Function parameter validation – other validation options

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

Some other options you can use for validating your input include:


tests the number of values being passed to the parameter – must be within the range (including end points ) specified


test the number of characters in a parameter value – must be within the specified range
[ValidatePattern(“\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b”)] ## IP Address

tests the input value against a regular expression – the value must match the pattern otherwise an error will be thrown


the value must be between the endpoints of the range specified

[ValidateSet(“Low”, “Average”, “High”)]

the value must be a member of the set of values specified

Using these, together with the ValidateScript and Validate  NotNullorEmpty options, provide you an easy way to test and validate your function inputs.  Much easier than writing your own code

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: