Skip to content

Latest commit

 

History

History
45 lines (30 loc) · 1.84 KB

validateset-attribute-declaration.md

File metadata and controls

45 lines (30 loc) · 1.84 KB
description ms.date ms.topic title
ValidateSet Attribute Declaration
09/13/2016
reference
ValidateSet Attribute Declaration

ValidateSet Attribute Declaration

The ValidateSetAttribute 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.

Syntax

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

Parameters

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

[ValidateSetAttribute("Steve")]
[ValidateSetAttribute("Steve","Mary")]

IgnoreCase (System.Boolean) Optional named parameter. The default value of true indicates that case is ignored. A value of false makes the cmdlet case-sensitive.

Remarks

  • 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 ValidateSetAttribute attribute is defined by the System.Management.Automation.Validatesetattribute class.

See Also

System.Management.Automation.Validatesetattribute

Writing a Windows PowerShell Cmdlet