Unary, binary, and ternary operators
As mentioned at the start of this chapter, operators can expect different numbers of arguments.
A unary operator requires a single argument (acting on a single item), and in PowerShell, this argument is normally placed on the right-hand side of the operator. For example, the -not
operator is a unary operator used as shown below:
-not $false
Several operators can be used as either unary or binary. The addition operator, +
, and subtraction operators can be used as unary operators:
+1
-1
Addition and subtraction operators may also be used as binary operators (acting on two items), that is, an operator that expects two arguments, one on the left and one on the right:
1 + 1
1 - 1
A third type of operator is one that expects three arguments, a ternary operator (acting on three items).
PowerShell only has one operator that is strictly classed as ternary. It is used to express a logical condition.
About the ternary operator
The ternary operator is a conditional...