An operator is a language token consisting of one or more characters that instructs the PowerShell parser to perform specific calculations, comparisons, assignments, type conversions, or stream redirections on values and expressions. These values are known as operands. Because PowerShell operates on structured .NET objects rather than raw text, its operators can manipulate primitive values, arrays, strings, collections, and object references directly.
Operators are the building blocks for arithmetic calculations, comparisons, logical decisions, and data manipulation throughout every PowerShell script.
Operator Categories
PowerShell organizes its operators into distinct functional families:
| Operator Category | Description | Primary Symbols / Tokens | Reference Guide |
|---|---|---|---|
| Unary Operators | Operate on a single operand to increment, decrement, negate, or invert truth states. | ++, --, +, -, ! |
Unary Operators |
| Arithmetic Operators | Perform standard mathematical calculations on numbers and concatenation/replication on strings and arrays. | +, -, *, /, % |
Arithmetic Operators |
| Relational Operators | Evaluate equality, comparative magnitude, wildcards, and regular expression patterns. | -eq, -ne, -gt, -lt, -like, -match |
Relational Operators |
| Logical Operators | Connect conditional statements and evaluate combined boolean logic with short-circuiting. | -and, -or, -not, -xor |
Logical Operators |
| Assignment Operators | Assign, modify, or append calculated values to target variables. | =, +=, -=, *=, /=, ??= |
Assignment Operators |
| Bitwise Operators | Manipulate individual binary bits within integer values and bitmasks. | -band, -bor, -bxor, -bnot, -shl, -shr |
Bitwise Operators |
| Redirection Operators | Route standard pipeline and diagnostic streams to files or merge streams. | >, >>, 2>, 2>&1, *> |
Redirection Operators |
| Type Operators | Validate, test, or safely convert the underlying .NET type of an object. | -is, -isnot, -as |
Type Operators |
| Other Operators | Perform specialized syntax tasks like ranges, string joining, splitting, and null coalescing. | .., -join, -split, ??, ?:, & |
Other Operators |
A Quick Comparison
The table below previews one representative operator from each category, to illustrate the breadth of what PowerShell operators cover.
| Category | Example | Result |
|---|---|---|
| Unary | -$x |
Negates the value of $x |
| Arithmetic | 10 % 3 |
1 |
| Relational | "abc" -eq "abc" |
$true |
| Logical | $true -and $false |
$false |
| Assignment | $x += 5 |
Adds 5 to $x and reassigns |
| Bitwise | 6 -band 3 |
2 |
| Redirection | Get-Process > out.txt |
Writes output to out.txt |
| Type | 5 -is [int] |
$true |
| Other | 1..5 |
1 2 3 4 5 |
Operator Precedence
When multiple operators appear in a single expression, PowerShell evaluates them in a specific order known as operator precedence. Operators with higher precedence are evaluated before operators with lower precedence.
From highest precedence to lowest:
1. Parentheses (Grouping): ( ... )
2. Subexpressions & Arrays: $( ... ), @( ... )
3. Member Access & Array Indexing: . , :: , [ ]
4. Unary Operators: ++, --, - (unary minus), !
5. Type Operators: -is, -isnot, -as
6. Arithmetic Multiplicative: *, /, %
7. Arithmetic Additive: +, - (binary minus)
8. Relational / Comparison: -eq, -ne, -gt, -lt, -like, -match
9. Logical Operators: -and, -or, -xor
10. Null-Coalescing & Ternary: ??, ?:
11. Assignment Operators: =, +=, -=, *=, /=, %=, ??=When an expression contains operators of equal precedence, PowerShell evaluates them from left to right, except for assignment operators, which evaluate from right to left.
10 + 5 * 2
(10 + 5) * 220
30Practical Example: Combining Multiple Operator Families
The following script combines arithmetic, relational, logical, assignment, and redirection operators to evaluate system memory usage and generate an operational threshold alert:
$TotalRamBytes = (Get-CimInstance -ClassName Win32_OperatingSystem).TotalVisibleMemorySize * 1KB
$FreeRamBytes = (Get-CimInstance -ClassName Win32_OperatingSystem).FreePhysicalMemory * 1KB
$UsedRamBytes = $TotalRamBytes - $FreeRamBytes
$PercentUsed = ($UsedRamBytes / $TotalRamBytes) * 100
$IsHighMemory = $PercentUsed -ge 80.0
$IsCritical = $PercentUsed -ge 95.0
$RequiresAlert = $IsHighMemory -or $IsCritical
$StatusLevel = $IsCritical ? "CRITICAL" : ($IsHighMemory ? "WARNING" : "HEALTHY")
$Report = [PSCustomObject]@{
TotalRAM_GB = [math]::Round($TotalRamBytes / 1GB, 2)
FreeRAM_GB = [math]::Round($FreeRamBytes / 1GB, 2)
PercentUsed = [math]::Round($PercentUsed, 2)
Status = $StatusLevel
AlertRequired = $RequiresAlert
}
$Report | Format-Table -AutoSize
$Report | Export-Csv -Path "$PSScriptRoot\memory-health.csv" -NoTypeInformationwhere:
* 1KBuses the arithmetic multiplication operator with a built-in size multiplier.-and/calculate numeric deltas and percentage ratios.-geis a relational operator testing if the operand is greater than or equal to a threshold.-oris a logical operator combining two boolean states.? :is the ternary operator selecting status values based on inline conditions.|pipes custom objects to formatting and CSV export cmdlets.
Execute the script from the console:
pwsh ./evaluate-system-thresholds.ps1TotalRAM_GB FreeRAM_GB PercentUsed Status AlertRequired
----------- ---------- ----------- ------ -------------
31.68 8.42 73.42 HEALTHY FalseInspect the redirected CSV artifact:
Get-Content -Path "$PSScriptRoot\memory-health.csv""TotalRAM_GB","FreeRAM_GB","PercentUsed","Status","AlertRequired"
"31.68","8.42","73.42","HEALTHY","False"