Arithmetic operators
Arithmetic operators are used to perform numeric calculations. The arithmetic operators in PowerShell are as follows:
- Addition:
+
- Subtraction:
-
- Multiplication:
*
- Division:
/
- Remainder:
%
As well as its use in numeric calculations, the addition operator may also be used with strings, arrays, and hashtables, and the multiplication operator may also be used with strings and arrays.
The following sections explore each of the operators listed previously.
Operator precedence
Operations are executed in a specific order depending on the operator used. For example, consider the following two simple calculations:
3 + 2 * 2
2 * 2 + 3
The result of both preceding expressions is 7 (2 multiplied by 2, then add 3) because the multiplication operator has higher precedence than the addition operator.
PowerShell includes a help document describing the precedence for each operator:
Get-Help about_Operator_Precedence...