header image

Validating parameters

Posted by: | July 8, 2013 | No Comment |

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

under: PowerShell Basics, PowerShell V3