February 2019
Intermediate to advanced
626 pages
15h 51m
English
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.
Read now
Unlock full access