Function parameter validation – other validation options

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

This entry was posted in Powershell Basics. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s