PowerShell comparison operators

Overview

Comparison operators let you specify conditions for comparing values and finding values that match specified patterns. The following table describes commonly used PowerShell comparison operators.

Details

Operator Convention Description
-eq, -ceq, -ieq = equals
-ne, -cne, -ine <> not equal
-gt, -cgt, -igt > greater than
-ge, -cge, -ige >= greater than or equal to
-lt, -clt, -ilt < less than
-le, -cle, -ile <= less than or equal to
-contains,
-ccontains,
-icontains
contains
-notcontains,
-cnotcontains,
-inotcontains
does not contain
-like like operator
-notlike negated like operator

There are three variants of most comparison operators. The basic variant is case-insensitive when making comparisons. In order to change this behaviour, precede the operator name with a “c” or an “i” as shown in the following example.

  • -eq = case-insensitive comparison
  • -ceq = case-sensitive comparison
  • -ieq = case-insensitive comparison

Obviously, case sensitivity only applies to strings.

See also

The Microsoft TechNet article about_Comparison_Operators

Advertisements
This entry was posted in powershell and tagged , . Bookmark the permalink.

One Response to PowerShell comparison operators

  1. Thomas says:

    Great post ! 🙂 Have nice day ! poswshbvii

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