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

Advertisements
This entry was posted in Powershell Basics. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s