Arithmetic operators
Arithmetic operators are used to perform numeric calculations. The operators available are the following:
- Addition:
+
- Subtraction:
-
- Multiplication:
*
- Division:
/
- Modulus:
%
- Shift left:
-shl
- Shift right:
-shr
As well as numeric calculations, the addition operator may also be used with strings, arrays, and hashtables; the multiplication operator may also be used with strings and arrays.
Operator precedence
Mathematical operations are executed in a specific order. For example, consider the following two simple calculations:
3 + 2 * 2 2 * 2 + 3
The result of both of the preceding expressions is 7
(2
multiplied by 2
, then add 3
).
PowerShell, and most other programming languages, will calculate elements of an expression using multiplication (*
), division (/
), and modulus (%
) first. Addition (+
) and subtraction (-
) are calculated next.
PowerShell has two additional operators in this category, -shl
and -shr
. These two have the lowest precedence and are only executed once all other operations...