As you would expect, PowerShell supports all of the normal arithmetic, logical, bitwise and comparison operators.  The sections below provide an overview of each of these operators, plus a few PowerShell specific operators.

Operator Meaning Example(s)
= Assignment operator.  Assigns the value of the right-hand operand to the variable specified in the left-hand operand.

Assignment chaining is also supported.
# Simple assignments. $foo = 1; $bar = 'xyzzy'; # Chained assignments (all variables to the left of the last '=' assume the assigned value). $foo = $bar = 999;
Operator Meaning Example(s)
+ Adds numeric values, concatenates strings, and . # Numeric addition. $foo = 19 + 39; # String concatenation. $foo = 'abc' + 'def'; # Add a single element to a one-dimension array (see also , below). $foo = @( 'apple', 'banana' ); $foo = $foo + 'cherry'; # Add a key/value pair to a hash table (again, see also , below). $objHash = $objHash + @{ 'mykey', 'myvalue' };
- Performs numeric subtraction or signs a value as negative. # Numeric subtraction. $foo = 19 - 39; # Signing. $theta = -180;
* Multiplies numeric values or duplicates strings and . # Numeric multiplication. $foo = 101 * 32; # String duplication (repetition).  In this example, the result is a # concatenated string of eighty hash characters. $foo = '#' * 80; # Array duplication (repetition).  In this example, the result is a # six element array containing alternate 'apple' and 'banana' values. $foo = @( 'apple', 'banana' ) * 3;
/ Numeric division. # Numeric division. $foo = 100 / 3;
% Modulus (or "modulo").  Returns the remainder of a division operation. # In this example, the result is 5, as 13 = (1 * 8) + 5. $foo = 13 % 8; (13 + 0) % 8 = 5 # Correct. (13 + 8) % 8 = 5 # Correct. (13 + 8 + 8) % 8 = 5 # Correct. (13 - 8) % 8 = 5 # Correct. (13 - 8 - 8) % 8 = -3 # Incorrect.
++ Increments the preceding variable by 1.  Can be a pre-increment or post-increment operation. # Pre-increment. Both $foo and $bar become 1. # $bar is pre-incremented (to become 1) and then assigned to $foo. $foo = 0; $bar = 0; $foo = ++$bar; # Post-increment. $foo remains as 0; $bar becomes 1. # $bar is assigned to $foo and then incremented. $foo = 0; $bar = 0; $foo = $bar++;
-- Decrements the preceding variable by 1.  Can be a pre-decrement or post-decrement operation. # Pre-decrement. Both $foo and $bar become -1. # $bar is pre-decremented (to become -1) and then assigned to $foo. $foo = 0; $bar = 0; $foo = --$bar; # Post-decrement. $foo remains as 0; $bar becomes -1. # $bar is assigned to $foo and then decremented. $foo = 0; $bar = 0; $foo = $bar--;

As with most programming languages, PowerShell's arithmetic operators are processed with the following order of precedence:

The arithmetic operators defined above all have shorthand notations when performing operations against a single variable, i.e.:

Shorthand Example Equivalent To
+= # Simple arithmetic. $foo += 3; # Append an item to a single-dimension array. $bar = @( 1, 5, 9 ); $bar += 12; # Append a sub-array to a multi-dimensional array. $foo = @( ('a1', 'b1', 'c1'), ('a2', 'b2', 'c2') ); $foo += ,@('a3', 'b3', 'c3'); # Add a key/value pair to a hash table. $objHash += @{ 'mykey', 'myvalue' }; # Simple arithmetic. $foo = $foo + 3; # Append an item to a single-dimension array. $bar = @( 1, 5, 9 ); $bar = $bar + 12; # Append a sub-array to a multi-dimensional array. $foo = @( ('a1', 'b1', 'c1'), ('a2', 'b2', 'c2') ); $foo = $foo + ,@('a3', 'b3', 'c3'); # Add a key/value pair to a hash table. $objHash = $objHash + @{ 'mykey', 'myvalue' };
-= $foo -= 9; $foo = $foo - 9;
*= $foo *= 2; $foo = $foo * 2;
/= $foo /= 9; $foo = $foo / 9;
%= %foo %= 3; $foo = $foo % 3;

PowerShell supports the following logical operators:

Operator Meaning Example
-and Returns $true if both conditions being tested are true (an intersection in set theory), i.e.:

($false -and $false) = $false ($false -and $true) = $false ($true -and $false) = $false ($true -and $true) = $true
if ( (condition) -and (condition) ) { action; }
-or Returns $true if either condition being tested are true (a union in set theory), i.e.:

($false -or $false) = $false ($false -or $true) = $true ($true -or $false) = $true ($true -or $true) = $true
if ( (condition) -or (condition) ) { action; }
-xor Exclusive OR.  Returns $true if one of the conditions being tested is true, but not both, i.e.:

($false -xor $false) = $false ($false -xor $true) = $true ($true -xor $false) = $true ($true -xor $true) = $false
if ( (condition) -xor (condition) ) { action; }
! or -not Returns $true if the proceeding condition is false, i.e.:

(! $true) = $false (! $false) = $true
if ( ! condition) { action; }
if ( -not condition) { action; }

PowerShell supports the following bitwise (boolean) operators:

Operator Meaning Example
-band Bitwise AND.  Compares each bit of the first operand with the corresponding bit of the second operand.  If both bits are set, the corresponding bit in the result will be set, for example: 1100 1010 ==== 1000
$a = [Convert]::ToInt32( '1100', 2); $b = [Convert]::ToInt32( '1010', 2); $c = $a -band $b; [Convert]::ToString( $c, 2 );    # Returns 1000.
-bor Bitwise OR.  Compares each bit of the first operand with the corresponding bit of the second operand.  If either bits are set, the corresponding bit in the result will be set, for example: 1100 1010 ==== 1110
$a = [Convert]::ToInt32( '1100', 2); $b = [Convert]::ToInt32( '1010', 2); $c = $a -bor $b; [Convert]::ToString( $c, 2 );    # Returns 1110.
-bxor Bitwise XOR (exclusive OR).  Compares each bit of the first operand with the corresponding bit of the second operand.  If either bits are set, but not both, the corresponding bit in the result will be set, for example: 1100 1010 ==== 0110
$a = [Convert]::ToInt32( '1100', 2); $b = [Convert]::ToInt32( '1010', 2); $c = $a -bxor $b; [Convert]::ToString( $c, 2 );    # Returns 0110.
-bnot Inverts the bits of the proceeding operand, for example: 1100 ==== 0011

-shl Performs a bitwise left-shift of the first operand, with the second operand determining how many bits to shift.  Zeros are brought in on the right-hand side (the least significant bit, or LSB).  Introduced in PowerShell V3.0. $a = [Convert]::ToInt32( '11110000', 2 ); $b = $a -shl 1;    # Shift one bit left (equivalent of multiplying by two).
-shr Performs a bitwise right-shift of the first operand, with the second operand determining how many bits to shift.  Zeros are brought in on the left-hand side (the most significant bit, or MSB).  Introduced in PowerShell V3.0. $a = [Convert]::ToInt32( '11110000', 2 ); $b = $a -shr 2;    # Shift two bits right (equivalent of dividing by four).

PowerShell supports numerous comparison operators, all of which behave differently when presented with (single value) input or compound input.  We'll first look at their behaviour when dealing with scalar input.

Operator Meaning Example
-lt
-clt
Returns $true if the first operand is less than the second.

When dealing with textual input, the -lt operator is case-insensitive.  To enforce case-sensitivity, use the -clt operator.
( 1 -lt 2 )    # Returns $true. ( 1 -lt 1 )    # Returns $false. ( 2 -lt 1 )    # Returns $false. ('a' -lt 'A')  # Returns $false. ('a' -clt 'A') # Returns $true.
-le
-cle
Returns $true if the first operand is less than or equal to the second; equivalent to <= in other languages.

When dealing with textual input, the -le operator is case-insensitive.  To enforce case-sensitivity, use the -cle operator.
( 1 -le 2 )    # Returns $true. ( 1 -le 1 )    # Returns $true. ( 2 -le 1 )    # Returns $false. ('A' -le 'a')  # Returns $true. ('A' -cle 'a') # Returns $false.
-eq
-ceq
Returns $true if both operands are the same.

When dealing with textual input, the -eq operator is case-insensitive.  To enforce case-sensitivity, use the -ceq operator.
( 1 -eq 2 )    # Returns $false. ( 1 -eq 1 )    # Returns $true. ( 2 -eq 1 )    # Returns $false. ('A' -eq 'a')  # Returns $true. ('A' -ceq 'a') # Returns $false.
-ne
-cne
Returns $true if the first operand does not equal the second.

When dealing with textual input, the -ne operator is case-insensitive.  To enforce case-sensitivity, use the -cne operator.
( 1 -ne 2 )    # Returns $true. ( 1 -ne 1 )    # Returns $false. ( 2 -ne 1 )    # Returns $true. ('A' -ne 'a')  # Returns $false. ('A' -cne 'a') # Returns $true.
-ge
-cge
Returns $true if the first operand is greater than or equal to the second; equivalent to >= in other languages.

When dealing with textual input, the -ge operator is case-insensitive.  To enforce case-sensitivity, use the -cge operator.
( 1 -ge 2 )    # Returns $false. ( 1 -ge 1 )    # Returns $true. ( 2 -ge 1 )    # Returns $true. ('a' -ge 'A')  # Returns $true. ('a' -cge 'A') # Returns $false.
-gt
-cgt
Returns $true if the first operand is greater than the second.

When dealing with textual input, the -gt operator is case-insensitive.  To enforce case-sensitivity, use the -cgt operator.
( 1 -gt 2 )    # Returns $false. ( 1 -gt 1 )    # Returns $false. ( 2 -gt 1 )    # Returns $true. ('A' -gt 'a')  # Returns $false. ('A' -cgt 'a') # Returns $true.
-like
-clike
Performs simple pattern matching against the given string value, returning true if the pattern matches.   Supports basic wildcards, such as ? (single character), * (one or more characters), [a-e] (range) and [aeiou] (set).  The -like operator is case-insensitive.  To enforce case-sensitivity, use the -clike operator. ('Lorem ipsum' -like 'l*')    # Returns $true. ('Lorem ipsum' -clike 'l*')   # Returns $false.
-notlike
-cnotlike
The same as -like and -clike, but Returns $true if a match isn't found. ('Lorem ipsum' -notlike 'l*')    # Returns $false. ('Lorem ipsum' -cnotlike 'l*')   # Returns $true.
-match
-cmatch
Performs (RegEx) pattern matching against the given string value, returning true if the pattern matches.

The -match operator is case-insensitive.  To enforce case-sensitivity, use the -cmatch operator.

If you use parenthesis for RegEx capturing, the captured values will be placed in the $matches (which is a ).
# Returns $true, and the $matches hash gets populated, e.g.: $matches[2] becomes Ipsum. ( 'Lorem Ipsum' -match '^([a-z]+)\s+([a-z]+)$' ); # Returns $false. ( 'Lorem Ipsum' -cmatch '^([a-z]+)\s+([a-z]+)$' );
-notmatch
-cnotmatch
The same as -match and -cmatch, but Returns $true if the RegEx does not match. # Returns $false (however, the $matches variable is still populated). ( 'Lorem Ipsum' -notmatch '^([a-z]+)\s+([a-z]+)$' ); # Returns $true. ( 'Lorem Ipsum' -cnotmatch '^([a-z]+)\s+([a-z]+)$' );

The operators described above can also be applied to compound types, such as .   In this mode of operation, they return a subset of values that match the given criteria.   To demonstrate this behaviour, we'll take a look at the -lt and -gt operators:

Operator Example
-lt # Return a subset of values using the -lt operator. $foo = @( 'apple', 'banana', 'cherry', 'damson', 'elderberry', 'fig' ); ($foo -lt 'd')    # Returns @( 'apple', 'banana', 'cherry' ).
-gt # Return a subset of values using the -gt operator. $foo = @( 'apple', 'banana', 'cherry', 'damson', 'elderberry', 'fig' ); ($foo -gt 'd')    # Returns @( 'damson', 'elderberry', 'fig' ).

The same theory applies to the remaining comparison operators, such as -le, -ge, -like, -match, Etc.

PowerShell supports four containment operators which provide a means of testing a collection, such as an , for the presence of a given value.  This negates the need to interate through the members of the given collection looking for a value of interest.  The four operators are described below.

Operator Meaning Example
-contains
-ccontains
Tests for the presence of a given value in a given collection, returning true if the value is found.

The -contains operator is case-insensitive.  To enforce case-sensitivity, use the -ccontains operator.
@( 'apple', 'banana', 'cherry' ) -contains 'banana'    # Returns $true. @( 'apple', 'banana', 'cherry' ) -contains 'BANANA'    # Returns $true (case ignored). @( 'apple', 'banana', 'cherry' ) -ccontains 'BANANA'   # Returns $false.
-notcontains
-cnotcontains
Tests for the absence of a given value in a given collection, returning true if the value is not found.

The -notcontains operator is case-insensitive.  To enforce case-sensitivity, use the -cnotcontains operator.
@( 'apple', 'banana', 'cherry' ) -notcontains 'banana'    # Returns $false. @( 'apple', 'banana', 'cherry' ) -notcontains 'BANANA'    # Returns $false (case ignored). @( 'apple', 'banana', 'cherry' ) -cnotcontains 'BANANA'   # Returns $true.
-in
-cin
Identical to -contains and -ccontains, but with their syntax reversed.

Introduced in PowerShell V3.0 in conjunction with the modified cmdlet, which supports an alternative, more natural, form of expression.

The -in operator is case-insensitive.  To enforce case-sensitivity, use the -cin operator.
Get-ChildItem | Where-Object Extension -in '.jpg', '.png'

...compared to PowerShell V2.0 syntax:

Get-ChildItem | Where-Object { '.jpg', '.png' -contains $_.Extension }
-notin
-cnotin
Identical to -notcontains and -cnotcontains, but with their syntax reversed.

Again, introduced in PowerShell V3.0 in conjunction with the revised cmdlet.

The -notin operator is case-insensitive.  To enforce case-sensitivity, use the -cnotin operator.
Get-Childitem | Where-Object Extension -notin '.log', '.tmp'

PowerShell supports three type operators; two for testing data types and one for casting data types.  The three operators are described below:

Operator Meaning Example
-is Determins if the first operarand's data type matches that of the second operand. if ( $suppliedTime -is [DateTime] ) { Write-Host -Object ( 'The month is {0}.' -f $suppliedTime.ToString('MMMM') ); }
-isnot Determines if the first operand's data type does not match that of the second operand. if ( $suppliedTime -isnot [DateTime] ) { Write-Warning -Object ( 'Please supply a valid date object.' ); }
-as PowerShell's native type casting operator.  Attempts to cast the value of the first operand as the data type of the second.

As discussed in the section, the -as operator should be avoided, as it doesn't generate an error when casting fails (it simply returns $null).  The safer option is to use the .NET Framework Convert class.
$datetime = $suppliedTime -as [DateTime]; if ( $datetime -eq $null ) { # Casting failed. }

Operator Meaning Example
.. Range operator.  Returns an array of integers ranging from the value of the first operand to the value of the second.  Ranges can be concatenated using a semi-colon. # Returns the integers from 1 to 10. 1..10 # Returns the integers from -5 to 5. -5..5 # Returns the integers from 10 down to 1. 10..1 # Returns the integers 1, 5 to 10 and 13. 1;5..10;13 # Returns the integers 0 to 180, and back to 0. 0..180;179..0 # Do something useful with a set of ranges. foreach ( $i in @(1..10;20..15) ) { $i; }