header image

PowerShell operators

Posted by: | February 24, 2019 Comments Off on PowerShell operators |

PowerShell has operators – lots of operators. This is a quick overview of the PowerShell Operators.

The obvious place to start is the arithmetic operators – see about_Arithmetic_Operators

+, –, *, / perform the four arithmetic operations

% is for modular arithmetic – get the remainder after division

-shl and –shr perform shift left and right operations for bitwise operations


Assignment operators are used to assign a value to a variable – see about_Assignment_Operators

= is the basic assignment

+=, –=, *=, /= and %= perform the appropriate arithmetic operation and assign the result

++, — increment and decrement a value respectively


Comparison operators are heavily used in branching and testing logic – see about_Comparison_Operators

-eq, ne equals and not equals

-gt, -ge, –lt, –le greater or lesser comparisons

-like, –notlike – wildcard comparisons

-match, notmatch – regular expression (shudder) comparisons

-contains, –notcontains, –in, –notin tests array membership

-replace – replace part of a string with another


By default comparison operators are case insensitive. To get a case sensitive operation give the operator a c prefix – -ceq rather than –eq. Likewise an i prefix states explicitly that you want a case insensitive comparison.


Logical operators – see about_Logical_Operators

-and, –or

-xor logical exclusive or

-not (also written as !) – negates following statement

-band, –bor, bxor, –bnot for working with binary


Type operators for testing or converting types – see about_Type_Operators

-is, –isnot – test a type

-as converts to the type


The help file about_operators covers a surprising set of operators – some you may not consider.

You should spend some time reading the operator help files so you get the best out of the many, many PowerShell operators

under: PowerShell

Comments are closed.