Converting VBScript's Xor Operator

Windows PowerShell

Definition: Performs a logical exclusion on two expressions.

Xor Operator

The XOR operator is a crazy one. XOR evaluates two expressions and returns True if the two are different; that is, if one expression is True and the other expression is False. If both expression are true (or false) then XOR returns False.

We told you it was crazy.

Here’s an example. This command evaluates the following two statements, then stores its verdict in the variable $a:

  • 23 is less than 12

  • 12 is greater than 40

Here’s the command

$a = 23 -gt 12 -xor 12 -lt 40

Because both expressions are true, if you run the command and then echo back the value of $a you’ll get the following:


Return to the VBScript to Windows PowerShell home page