Monthly Archive

Categories

PowerShell operators

PowerShell has operators – lots of operators. So many operators that it took us TWO chapters to work through them all in PowerShell in Action, third edition - https://www.manning.com/books/windows-powershell-in-action-third-edition. Here’s how you can discover the PowerShell operators.

PS> Get-Help about*operator*

Name
----
about_Arithmetic_Operators
about_Assignment_Operators
about_Comparison_Operators
about_Logical_Operators
about_Operators
about_Operator_Precedence
about_Type_Operators

A quick listing gives us:

Arithmetic operators (+, -, *, /, %)

Assignment operators (=, +=, -=, *=, /=, %=)

Comparison operators (-eq, -ne, -gt, -lt, -le, -ge)  (-match, -notmatch) (-like, -notlike)

(-in, -notin, -contains,  -notcontains) (-bAND, -bOR, -bXOR, -bNOT)

Logical opertors (-and, -or, -xor, -not, !)

Redirection operators (>, >>, 2>, 2>, and 2>&1)

Type operators (-is, -isnot, -as)

And a  bunch of special operators @(), & (call), [] (cast),  comma, dot, –f , index opertor, pipeline operator, range operator, :: static member operator, $()

Also don’t forget –split, –join, –replace

Comments are closed.