February 2019
Intermediate to advanced
626 pages
15h 51m
English
ValidateScript executes an arbitrary block of code against each of the arguments for a parameter. If the argument is an array, each element is tested. One common use for ValidateScript is to test whether a path exists, for example:
function Test-ValidateScript { [CmdletBinding()] param ( [ValidateScript( { Test-Path $_ -PathType Leaf } )] [String]$Path )}
ValidateScript can contain just about anything a developer desires, although it is generally recommended to keep validation scripts short. In PowerShell Core, ValidateScript gains an optional ErrorMessage parameter that replaces the default message, which repeats the failed script to the end user:
function Test-ValidateScript { [CmdletBinding()] param ( [ValidateScript( ...Read now
Unlock full access