Arithmetic operators calculate mathematical values, combine text strings, replicate collections, and determine division remainders. Unlike traditional shells like Windows Command Prompt (which requires set /a and is restricted to 32-bit integers), PowerShell natively handles floating-point numbers, automatically widens numeric types to prevent overflow, and overloads arithmetic symbols to manipulate strings and arrays.
PowerShell includes five core arithmetic operators: addition, subtraction, multiplication, division, and modulus (remainder).
Core Arithmetic Operators
| Operator | Description | PowerShell Syntax | Result |
|---|---|---|---|
+ |
Addition / Concatenation | 15 + 5 |
20 |
- |
Subtraction | 25 - 8 |
17 |
* |
Multiplication / Replication | 6 * 7 |
42 |
/ |
Division | 40 / 8 |
5 |
% |
Modulo (Remainder) | 17 % 5 |
2 |
$a = 15
$b = 4
Write-Output ($a + $b)
Write-Output ($a - $b)
Write-Output ($a * $b)
Write-Output ($a / $b)
Write-Output ($a % $b)./arithmetic-basics.ps119
11
60
3.75
3where:
/always performs floating-point division by default, even when dividing two integers. Note the result3.75above, not a truncated integer.%returns the remainder left over after dividing$aby$b.
Operator Overloading and Type Behaviors
In PowerShell, arithmetic operators behave differently depending on the data type of the left-hand operand. The same symbol (+, *) performs different operations based on the data type of its operands: numeric addition for numbers, string concatenation, and array combination.
Addition (+)
- Numbers: Performs numeric addition.
- Strings: Concatenates strings together.
- Arrays: Merges collections into a new, combined array.
10 + 25
"Power" + "Shell"
@(1, 2) + @(3, 4)35
PowerShell
1
2
3
4Subtraction (-)
Subtracts numbers or calculates time differences between dates:
100 - 35
(Get-Date "2026-01-01") - (Get-Date "2026-12-25")65
Days : -358
Hours : 0
Minutes : 0
Seconds : 0
Milliseconds : 0
Ticks : -309312000000000
TotalDays : -358
TotalHours : -8592
TotalMinutes : -515520
TotalSeconds : -30931200
TotalMilliseconds : -30931200000Multiplication (*)
- Numbers: Multiplies values.
- String Replication: Repeats a string a specified number of times.
- Array Replication: Duplicates array elements into a new array.
8 * 5
"-" * 20
@("NodeA", "NodeB") * 240
--------------------
NodeA
NodeB
NodeA
NodeBDivision (/)
Divides two numbers. Unlike languages like C# or Python 2 that truncate non-divisible integers, PowerShell automatically converts integer division to a System.Double if there is a remainder:
10 / 2
7 / 2
(7 / 2).GetType().Name5
3.5
DoubleModulo (%)
Calculates the integer remainder left over after dividing the left operand by the right operand. Modulo is frequently used in automation for running tasks at specific intervals, formatting alternating rows, or distributing workloads across worker pools:
10 % 3
15 % 51
0Operator Precedence
Operator precedence defines the sequence in which PowerShell calculates compound expressions. Multiplicative operators are evaluated before additive operators:
| # | Operator | Description |
|---|---|---|
| 1 | Parentheses | () [Highest Precedence] |
| 2 | Unary Operators | -, !, ++, -- |
| 3 | Multiplicative Operators | *, /, % |
| 4 | Additive Operators | +, - [Lowest Precedence] |
When two operators share the same precedence tier (such as * and /), PowerShell evaluates them from left to right:
$resultA = 10 + 5 * 2
$resultB = (10 + 5) * 2
$resultC = 100 / 5 * 2
[PSCustomObject]@{
ExpressionA = "10 + 5 * 2"
ResultA = $resultA
ExpressionB = "(10 + 5) * 2"
ResultB = $resultB
ExpressionC = "100 / 5 * 2"
ResultC = $resultC
}pwsh ./precedence-rules.ps1ExpressionA : 10 + 5 * 2
ResultA : 20
ExpressionB : (10 + 5) * 2
ResultB : 30
ExpressionC : 100 / 5 * 2
ResultC : 40Numeric Multipliers
PowerShell features built-in size multiplier suffixes that simplify byte calculations in system administration tasks:
| Suffix | Multiplier | Exact Decimal Bytes |
|---|---|---|
KB |
Kilobyte ($1024$) | $1,024$ |
MB |
Megabyte ($1024^2$) | $1,048,576$ |
GB |
Gigabyte ($1024^3$) | $1,073,741,824$ |
TB |
Terabyte ($1024^4$) | $1,099,511,627,776$ |
PB |
Petabyte ($1024^5$) | $1,125,899,906,842,624$ |
These multipliers can be combined directly with arithmetic operators:
50GB
10GB / 500MB53687091200
20.48Practical Example: Workload Chunking and Capacity Planning
The following script uses arithmetic operators (-, /, *, %) to inspect disk capacity, calculate utilization percentages, and distribute batch processing jobs across parallel worker queues:
param (
[int]$TotalJobs = 23,
[int]$WorkerCount = 4
)
$Drive = Get-CimInstance -ClassName Win32_LogicalDisk -Filter "DeviceID='C:'"
$TotalBytes = $Drive.Size
$FreeBytes = $Drive.FreeSpace
$UsedBytes = $TotalBytes - $FreeBytes
$PercentUsed = ($UsedBytes / $TotalBytes) * 100
$JobsPerWorker = [math]::Floor($TotalJobs / $WorkerCount)
$RemainingJobs = $TotalJobs % $WorkerCount
[PSCustomObject]@{
DriveTested = $Drive.DeviceID
TotalGB = [math]::Round($TotalBytes / 1GB, 2)
UsedGB = [math]::Round($UsedBytes / 1GB, 2)
PercentUsed = [math]::Round($PercentUsed, 1)
TotalBatchJobs = $TotalJobs
AssignedWorkers = $WorkerCount
BaseJobsPerNode = $JobsPerWorker
LeftoverJobs = $RemainingJobs
}where:
$TotalBytes - $FreeBytesuses subtraction to calculate consumed storage.($UsedBytes / $TotalBytes) * 100uses division and multiplication to calculate capacity percentage.1GBis the built-in numeric multiplier for byte conversion.[math]::Floor($TotalJobs / $WorkerCount)divides jobs evenly across nodes.$TotalJobs % $WorkerCountuses modulo to determine how many remaining jobs must be assigned to worker overflow pools.
Execute the script from the console:
pwsh ./compute-capacity-and-workers.ps1 -TotalJobs 23 -WorkerCount 4DriveTested : C:
TotalGB : 255.4
UsedGB : 213.25
PercentUsed : 83.5
TotalBatchJobs : 23
AssignedWorkers : 4
BaseJobsPerNode : 5
LeftoverJobs : 3