The ValidateSet attribute

ValidateSet tests whether the specified argument, or each of an array of arguments, exists in a set of possible values:

function Test-ValidateSet {
[CmdletBinding()]
param (
[ValidateSet('One', 'Two', 'Three')]
[String]$Value
)
}

The set of values must be hardcoded in the attribute, it cannot be derived from a variable or another command. By default, the set is not case-sensitive. If it is desirable, the set can be made case-sensitive by using the IgnoreCase named parameter:

function Test-ValidateSet {
[CmdletBInding()]
param (
[ValidateSet('One', 'Two', 'Three', IgnoreCase = $false)]
[String]$Value
)
}

Like ValidatePattern and ValidateSet, ValidateSet gains an optional ErrorMessage parameter in PowerShell Core.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.172.115