Simple Operators
Once you have defined your data, the next step is to work with it.
Arithmetic Operators
The arithmetic operators allow you to perform mathematical operations on your data.
Windows PowerShell arithmetic operators | |
|---|---|
Operator | Meaning |
| The addition operator: $leftValue + $rightValue When used with numbers, returns their sum. When used with strings, returns a new string created by appending the second string to the first. When used with arrays, returns a new array created by appending the second array to the first. When used with hashtables, returns a new hashtable created by merging the two hashtables. Since hashtable keys must be unique, PowerShell returns an error if the second hashtable includes any keys already defined in the first hashtable. When used with any other type,
PowerShell uses that type’s addition operator ( |
| The subtraction operator: $leftValue - $rightValue When used with numbers, returns their difference. This operator does not apply to strings. This operator does not apply to arrays. This operator does not apply to hashtables. When used with any other type,
PowerShell uses that type’s subtraction operator ( |
| The multiplication operator: $leftValue * $rightValue When used with numbers, returns their product. When used with
strings ( When used with
arrays ( |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access