Export (0) Print
Expand All
2 out of 6 rated this helpful - Rate this topic

ValidateSet Attribute Declaration

The ValidateSet attribute specifies a set of possible values for a cmdlet parameter argument. This attribute can also be used by Windows PowerShell functions.

When this attribute is specified, the Windows PowerShell runtime determines whether the supplied argument for the cmdlet parameter matches an element in the supplied element set. The cmdlet is run only if the parameter argument matches an element in the set. If no match is found, an error is thrown by the Windows PowerShell runtime.

[ValidateSet(params string[] validValues)]
[ValidateSet(params string[] validValues, Named Parameters)]

Parameters

ValidValues (String)
Required. Specifies the valid parameter element values. The following sample shows how to specify one element or multiple elements.

[ValidateSet("Steve")]
[ValidateSet("Steve","Mary")]
IgnoreCase (Boolean)
Optional named parameter. The default value of true indicates that case is ignored. A value of false makes the cmdlet case-sensitive.

  • For more information about how to declare this attribute, see How to Declare Input Validation Rules.

  • This attribute can be used only once per parameter.

  • If the parameter value is an array, every element of the array must match an element of the attribute set.

  • The ValidateSet attribute is defined by the ValidateSet class.

Reference

ValidateSet

Other Resources

How to Declare Input Validation Rules
Writing a Windows PowerShell Cmdlet



Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.