11---
22description : Lists the PowerShell operators in precedence order.
33Locale : en-US
4- ms.date : 06/29/2021
4+ ms.date : 12/30/2025
55online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_operator_precedence?view=powershell-5.1&WT.mc_id=ps-gethelp
66schema : 2.0.0
77title : about_Operator_Precedence
@@ -33,15 +33,15 @@ evaluated. Operators on the same line, or in the same group, have equal
3333precedence.
3434
3535The Operator column lists the operators. The Reference column lists the
36- PowerShell Help topic in which the operator is described. To display the topic,
37- type ` Get-Help <topic-name> ` .
36+ PowerShell Help topic in which the operator is described. To display the topic
37+ interactively, use ` Get-Help -Name <topic-name> ` .
3838
3939| OPERATOR | REFERENCE |
4040| --------------------------- | ------------------------------------ |
4141| ` $() @() () @{} ` | [ about_Operators] [ ops ] |
42- | ` . ?. ` (member access) | [ about_Operators] [ ops ] |
42+ | ` . ` (member access) | [ about_Operators] [ ops ] |
4343| ` :: ` (static) | [ about_Operators] [ ops ] |
44- | ` [0] ?[0] ` (index operator) | [ about_Operators] [ ops ] |
44+ | ` [0] ` (index operator) | [ about_Operators] [ ops ] |
4545| ` [int] ` (cast operators) | [ about_Operators] [ ops ] |
4646| ` -split ` (unary) | [ about_Split] [ split ] |
4747| ` -join ` (unary) | [ about_Join] [ join ] |
@@ -85,16 +85,13 @@ that happens.
8585| ------------------------------------------------------- | ------------------------------------ |
8686| ` . ` (dot-source) | [ about_Operators] [ ops ] |
8787| ` & ` (call) | [ about_Operators] [ ops ] |
88- | ` ? <if-true> : <if-false> ` (Ternary operator) | [ about_Operators] [ ops ] |
89- | ` ?? ` (null-coalese operator) | [ about_Operators] [ ops ] |
9088| <code >| ; </code > (pipeline operator) | [ about_Operators] [ ops ] |
9189| ` > >> 2> 2>> 2>&1 ` | [ about_Redirection] [ redir ] |
92- | <code >&& | ;| ; </code > (pipeline chain operators) | [ about_Operators] [ ops ] |
93- | ` = += -= *= /= %= ??= ` | [ about_Assignment_Operators] [ assign ] |
90+ | ` = += -= *= /= %= ` | [ about_Assignment_Operators] [ assign ] |
9491
9592## Examples
9693
97- The following two commands show the arithmetic operators and the effect of
94+ The following two examples show the arithmetic operators and the effect of
9895using parentheses to force PowerShell to evaluate the enclosed part of the
9996expression first.
10097
@@ -107,28 +104,28 @@ PS> (2 + 3) * 4
107104```
108105
109106The following example gets the read-only text files from the local directory
110- and saves them in the ` $read_only ` variable.
107+ and saves them in the ` $readOnly ` variable.
111108
112109``` powershell
113- $read_only = Get-ChildItem *.txt | Where-Object {$_.IsReadOnly}
110+ $readOnly = Get-ChildItem -Path *.txt | Where-Object { $_.IsReadOnly }
114111```
115112
116113It is equivalent to the following example.
117114
118115``` powershell
119- $read_only = ( Get-ChildItem *.txt | Where-Object {$_.IsReadOnly} )
116+ $readOnly = (Get-ChildItem -Path *.txt | Where-Object { $_.IsReadOnly } )
120117```
121118
122119Because the pipeline operator (` | ` ) has a higher precedence than the assignment
123120operator (` = ` ), the files that the ` Get-ChildItem ` cmdlet gets are sent to the
124121` Where-Object ` cmdlet for filtering before they are assigned to the
125- ` $read_only ` variable.
122+ ` $readOnly ` variable.
126123
127124The following example demonstrates that the index operator takes precedence
128125over the cast operator.
129126
130127This expression creates an array of three strings. Then, it uses the index
131- operator with a value of 0 to select the first object in the array, which is
128+ operator with a value of ` 0 ` to select the first object in the array, which is
132129the first string. Finally, it casts the selected object as a string. In this
133130case, the cast has no effect.
134131
@@ -163,7 +160,7 @@ PS> (2 -gt 4) -and 1
163160False
164161```
165162
166- If the -and operator had higher precedence, the answer would be TRUE.
163+ If the ` -and ` operator had higher precedence, the result would be TRUE.
167164
168165``` powershell
169166PS> 2 -gt (4 -and 1)
@@ -176,6 +173,27 @@ parentheses to force the evaluation order, even when it forces the default
176173operator precedence. The parentheses make your intentions clear to people who
177174are reading and maintaining your scripts.
178175
176+ The following example demonstrates the precedence between the ` -and ` and ` -or `
177+ logical operators.
178+
179+ ``` powershell
180+ PS> $true -or $false -and $false
181+ False
182+ ```
183+
184+ In other languages such as C#, logical AND typically has a higher precedence
185+ than logical OR, so you may expect the above expression to yield TRUE.
186+
187+ However, the ` -and ` and ` -or ` operators have equal precedence in PowerShell.
188+ They are evaluated from the left to right as they appear within the expression.
189+ As ` $true -or $false ` is TRUE and ` $true -and $false ` is FALSE, the result of
190+ the expression is FALSE.
191+
192+ > [ !IMPORTANT]
193+ > Other contexts within PowerShell such as [ WMI Query Language (WQL)] [ wql ] and
194+ > the Active Directory filter have their own operator precedence that might
195+ > differ from PowerShell logical operator precedence.
196+
179197## See also
180198
181199- [ about_Operators] [ ops ]
@@ -189,7 +207,7 @@ are reading and maintaining your scripts.
189207- [ about_Split] [ split ]
190208- [ about_Type_Operators] [ type ]
191209
192- <!-- reference links -->
210+ <!-- link references -->
193211[ math ] : about_Arithmetic_Operators.md
194212[ assign ] : about_Assignment_Operators.md
195213[ compare ] : about_Comparison_Operators.md
@@ -200,3 +218,4 @@ are reading and maintaining your scripts.
200218[ scopes ] : about_Scopes.md
201219[ split ] : about_Split.md
202220[ type ] : about_Type_Operators.md
221+ [ wql ] : about_WQL.md
0 commit comments