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 ( |
Get Windows PowerShell Quick Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.