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

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>