-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Restructure about_Logical_Operators and add -and/-or precedence example
#12622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Restructure about_Logical_Operators and add -and/-or precedence example
#12622
Conversation
This shifts about some of the existing content and adds a new header for Syntax. It also adds link references and makes minor formatting changes.
This removes operators added in newer PS versions from the PS 5.1 about_Operator_Precedence doc. The PS 5.1 about_Operators doc already doesn't include new operators like ??.
This adds an example involving both -and and -or to about_Operator_Precedence. It demonstrates the equal precedence between the two operators and calls out how this differs from other languages such as C#. It also notes that other contexts *within* PowerShell such as WQL and the AD filter have their own operator precedence which might differ (in both aforementioned cases, AND has higher precedence than OR).
PoliCheck Scan ReportThe following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans. ✅ No issues foundMore information about PoliCheckInformation: PoliCheck | Severity Guidance | Term |
|
Regarding the invalid links above, I see now that I see the |
PR Summary
In this PR:
about_Logical_Operators, by shifting about some of the existing content and adding a newSyntaxheader.-and/-or/-xorequal precedence note toabout_Logical_Operators.about_Operator_Precedencedoc (in line with 5.1'sabout_Operatorsdoc).-and/-orprecedence example toabout_Operator_Precedence.PR Context
The main motivation behind this PR was to highlight
-and/-or's equal precedence, which is a departure from other languages like C# and other fields like mathematics. This behavior is likely surprising to users coming from other languages/fields.There are also other contexts within PowerShell that have different operator precedence, like WQL and the AD filter (both of which give higher precedence to their AND operator). The AD filter especially is a source of confusion (users often mistakenly confuse AD filter syntax with PowerShell syntax and pass a script block to
Get-AD* -Filter).Based on above, I felt PowerShell's
-and/-orprecedence needed additional attention in bothabout_Logical_Operatorsandabout_Operator_Precedence.A real-world example where a user was surprised by PowerShell's behavior can be found here.
PR Checklist