Categories

Case sensitive operators

PowerShell is more or less case insensitive so the operation in my previous post

$_.Substring(3,1) -ne "T"

will trigger on “T” or “t”

If you only want the uppercase version to fail then you can use the case sensitive version of –ne  which is –cne.

This changes the script to:

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

You can read more about the comparison operators in

get-help about_Comparison_Operators

Leave a Reply