Monthly Archive


Validating parameters

PowerShell provides a number of ways of validating the values input to the parameters in your scripts. One such way is Validate script. I came across an interesting question where the inquirer wanted to test an input parameter and throw an error if the 4th character was a “T”

One solution is:

function ptest {
[ValidateScript({$_.Substring(3,1) -ne "T" })]
Write-Host "$server"

Alternatively use a regular expression

Leave a Reply