Once you have defined your data, the next step is to work with it.
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 ( This operator does not apply to hashtables. When used with any other
type, PowerShell uses that type’s multiplication operator
( |
| The division operator: $leftValue / $rightValue When used with numbers, returns their quotient (in floating-point format.) 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 multiplication operator ( |
| The modulus operator: $leftValue % $rightValue When used with numbers, returns the remainder of their division. 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 multiplication operator ( |
| Assignment operators: $variable <operator>= value These
operators match the simple arithmetic operators ( |
The System.Math class in the .NET Framework offers many powerful operations in addition to the native operators supported by PowerShell:
See the section named “Working with the .NET Framework” to learn more about using PowerShell to interact with the .NET Framework.
The logical operators allow you to compare Boolean values.
Windows PowerShell logical operators | |
---|---|
Operator | Meaning |
| Logical AND: $leftValue -and $rightValue Returns You
can combine several PowerShell implements the
|
| Logical OR: $leftValue -or $rightValue Returns You
can combine several PowerShell implements the
|
| Logical Exclusive OR: Returns |
-not | Logical NOT: -not $value Returns |
The binary operators allow you to apply the Boolean logical
operators bit by bit to the operator’s arguments. When comparing bits,
a 1
represents $true
, while a 0
represents $false
.
Windows PowerShell binary operators | |
---|---|
Operator | Meaning |
| Binary AND: $leftValue -band $rightValue Returns a number where bits are set to 1 if the bits of
the lefthand and righthand arguments at that position are both
For example: |
| Binary OR: $leftValue -bor $rightValue Returns a number
where bits are set to For example: |
| Binary Exclusive OR: $leftValue -bxor $rightValue Returns a number
where bits are set to For example: |
| Binary NOT: Returns a number where bits
are set to For example: |
PowerShell supports several other simple operators.
Other Windows PowerShell operators | |
---|---|
Operator | Meaning |
| The replace operator: “target” –replace “pattern”,”replacement” Returns a new string, where the text in By default,
PowerShell performs a case-insensitive comparison. The
If the regular-expression pattern contains named captures or capture groups, the replacement string may reference those as well. For example: For more information on the details of regular expressions, see the “Regular Expression Reference” appendix. |
| The format operator: <Format String> -f <Value Array> Returns a string, where the format items in the format string have been replaced with the text equivalent of the values in the value array. For example: The format string for the
format operator is exactly the format string supported by the
.NET For more details about the syntax of the format string, see the “.NET String Formatting” appendix. |
| The type conversion operator: $value –as [Type] Returns For example: |
3.144.84.155