Skip to content

Commit 0f79c66

Browse files
Restructure about_Logical_Operators
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.
1 parent 4a6a36f commit 0f79c66

4 files changed

Lines changed: 168 additions & 124 deletions

File tree

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the operators that connect statements in PowerShell.
33
Locale: en-US
4-
ms.date: 08/29/2022
4+
ms.date: 12/30/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_logical_operators?view=powershell-5.1&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Logical_Operators
@@ -17,10 +17,30 @@ Describes the operators that connect statements in PowerShell.
1717
The PowerShell logical operators connect expressions and statements, allowing
1818
you to use a single expression to test for multiple conditions.
1919

20-
For example, the following statement uses the and operator and the or operator
21-
to connect three conditional statements. The statement is true only when the
22-
value of $a is greater than the value of $b, and either $a or $b is less than
23-
20.
20+
Statements that use the logical operators return boolean (TRUE or FALSE)
21+
values.
22+
23+
The PowerShell logical operators evaluate only the statements required to
24+
determine the truth value of the statement. If the left operand in a statement
25+
that contains the `-and` operator is FALSE, the right operand isn't evaluated.
26+
If the left operand in a statement that contains the `-or` statement is TRUE,
27+
the right operand isn't evaluated. As a result, you can use these statements in
28+
the same way that you would use the `if` statement.
29+
30+
## Syntax
31+
32+
The syntax of the logical operators is as follows:
33+
34+
```Syntax
35+
<statement> {-and | -or | -xor} <statement>
36+
{! | -not} <statement>
37+
```
38+
39+
## Examples
40+
41+
The following example uses the `-and` and `-or` operators to connect three
42+
conditional statements. The result is TRUE only when the value of `$a` is
43+
greater than the value of `$b`, and either `$a` or `$b` is less than `20`.
2444

2545
```powershell
2646
($a -gt $b) -and (($a -lt 20) -or ($b -lt 20))
@@ -46,38 +66,29 @@ PowerShell supports the following logical operators.
4666
(1 -eq 1) -xor (2 -eq 2) # Result is False
4767
```
4868

49-
- Logical not (`-not`) or (`!`) - Negates the statement that follows.
69+
- Logical NOT (`-not`) or (`!`) - Negates the statement that follows.
5070

5171
```powershell
5272
-not (1 -eq 1) # Result is False
5373
!(1 -eq 1) # Result is False
5474
```
5575

56-
The previous examples also use the equal to comparison operator `-eq`. For more
57-
information, see [about_Comparison_Operators](about_Comparison_Operators.md).
58-
The examples also use the Boolean values of integers. The integer 0 has a value
59-
of FALSE. All other integers have a value of TRUE.
60-
61-
The syntax of the logical operators is as follows:
62-
63-
```Syntax
64-
<statement> {-and | -or | -xor} <statement>
65-
{! | -not} <statement>
66-
```
67-
68-
Statements that use the logical operators return Boolean (TRUE or FALSE)
69-
values.
70-
71-
The PowerShell logical operators evaluate only the statements required to
72-
determine the truth value of the statement. If the left operand in a statement
73-
that contains the and operator is FALSE, the right operand isn't evaluated. If
74-
the left operand in a statement that contains the or statement is TRUE, the
75-
right operand isn't evaluated. As a result, you can use these statements in
76-
the same way that you would use the `if` statement.
76+
The previous examples also use the equality comparison operator, `-eq`. For
77+
more information, see [about_Comparison_Operators][03]. The examples also use
78+
the boolean values of integers. The integer `0` has a boolean value of FALSE.
79+
All other integers have a value of TRUE.
7780

7881
## See also
7982

80-
- [about_Operators](about_Operators.md)
81-
- [about_Comparison_operators](about_Comparison_Operators.md)
82-
- [about_If](about_If.md)
83-
- [Compare-Object](xref:Microsoft.PowerShell.Utility.Compare-Object)
83+
- [about_Operators][02]
84+
- [about_Operator_Precedence][01]
85+
- [about_Comparison_Operators][03]
86+
- [about_If][04]
87+
- [Compare-Object][05]
88+
89+
<!-- link references -->
90+
[01]: about_Operator_Precedence.md
91+
[02]: about_Operators.md
92+
[03]: about_Comparison_Operators.md
93+
[04]: about_If.md
94+
[05]: xref:Microsoft.PowerShell.Utility.Compare-Object
Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the operators that connect statements in PowerShell.
33
Locale: en-US
4-
ms.date: 08/29/2022
4+
ms.date: 12/30/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_logical_operators?view=powershell-7.4&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Logical_Operators
@@ -17,10 +17,30 @@ Describes the operators that connect statements in PowerShell.
1717
The PowerShell logical operators connect expressions and statements, allowing
1818
you to use a single expression to test for multiple conditions.
1919

20-
For example, the following statement uses the and operator and the or operator
21-
to connect three conditional statements. The statement is true only when the
22-
value of $a is greater than the value of $b, and either $a or $b is less than
23-
20.
20+
Statements that use the logical operators return boolean (TRUE or FALSE)
21+
values.
22+
23+
The PowerShell logical operators evaluate only the statements required to
24+
determine the truth value of the statement. If the left operand in a statement
25+
that contains the `-and` operator is FALSE, the right operand isn't evaluated.
26+
If the left operand in a statement that contains the `-or` statement is TRUE,
27+
the right operand isn't evaluated. As a result, you can use these statements in
28+
the same way that you would use the `if` statement.
29+
30+
## Syntax
31+
32+
The syntax of the logical operators is as follows:
33+
34+
```Syntax
35+
<statement> {-and | -or | -xor} <statement>
36+
{! | -not} <statement>
37+
```
38+
39+
## Examples
40+
41+
The following example uses the `-and` and `-or` operators to connect three
42+
conditional statements. The result is TRUE only when the value of `$a` is
43+
greater than the value of `$b`, and either `$a` or `$b` is less than `20`.
2444

2545
```powershell
2646
($a -gt $b) -and (($a -lt 20) -or ($b -lt 20))
@@ -46,38 +66,29 @@ PowerShell supports the following logical operators.
4666
(1 -eq 1) -xor (2 -eq 2) # Result is False
4767
```
4868

49-
- Logical not (`-not`) or (`!`) - Negates the statement that follows.
69+
- Logical NOT (`-not`) or (`!`) - Negates the statement that follows.
5070

5171
```powershell
5272
-not (1 -eq 1) # Result is False
5373
!(1 -eq 1) # Result is False
5474
```
5575

56-
The previous examples also use the equal to comparison operator `-eq`. For more
57-
information, see [about_Comparison_Operators](about_Comparison_Operators.md).
58-
The examples also use the Boolean values of integers. The integer 0 has a value
59-
of FALSE. All other integers have a value of TRUE.
60-
61-
The syntax of the logical operators is as follows:
62-
63-
```Syntax
64-
<statement> {-and | -or | -xor} <statement>
65-
{! | -not} <statement>
66-
```
67-
68-
Statements that use the logical operators return Boolean (TRUE or FALSE)
69-
values.
70-
71-
The PowerShell logical operators evaluate only the statements required to
72-
determine the truth value of the statement. If the left operand in a statement
73-
that contains the and operator is FALSE, the right operand isn't evaluated. If
74-
the left operand in a statement that contains the or statement is TRUE, the
75-
right operand isn't evaluated. As a result, you can use these statements in
76-
the same way that you would use the `if` statement.
76+
The previous examples also use the equality comparison operator, `-eq`. For
77+
more information, see [about_Comparison_Operators][03]. The examples also use
78+
the boolean values of integers. The integer `0` has a boolean value of FALSE.
79+
All other integers have a value of TRUE.
7780

7881
## See also
7982

80-
- [about_Operators](about_Operators.md)
81-
- [about_Comparison_operators](about_Comparison_Operators.md)
82-
- [about_If](about_If.md)
83-
- [Compare-Object](xref:Microsoft.PowerShell.Utility.Compare-Object)
83+
- [about_Operators][02]
84+
- [about_Operator_Precedence][01]
85+
- [about_Comparison_Operators][03]
86+
- [about_If][04]
87+
- [Compare-Object][05]
88+
89+
<!-- link references -->
90+
[01]: about_Operator_Precedence.md
91+
[02]: about_Operators.md
92+
[03]: about_Comparison_Operators.md
93+
[04]: about_If.md
94+
[05]: xref:Microsoft.PowerShell.Utility.Compare-Object
Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the operators that connect statements in PowerShell.
33
Locale: en-US
4-
ms.date: 08/29/2022
4+
ms.date: 12/30/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_logical_operators?view=powershell-7.5&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Logical_Operators
@@ -17,10 +17,30 @@ Describes the operators that connect statements in PowerShell.
1717
The PowerShell logical operators connect expressions and statements, allowing
1818
you to use a single expression to test for multiple conditions.
1919

20-
For example, the following statement uses the and operator and the or operator
21-
to connect three conditional statements. The statement is true only when the
22-
value of $a is greater than the value of $b, and either $a or $b is less than
23-
20.
20+
Statements that use the logical operators return boolean (TRUE or FALSE)
21+
values.
22+
23+
The PowerShell logical operators evaluate only the statements required to
24+
determine the truth value of the statement. If the left operand in a statement
25+
that contains the `-and` operator is FALSE, the right operand isn't evaluated.
26+
If the left operand in a statement that contains the `-or` statement is TRUE,
27+
the right operand isn't evaluated. As a result, you can use these statements in
28+
the same way that you would use the `if` statement.
29+
30+
## Syntax
31+
32+
The syntax of the logical operators is as follows:
33+
34+
```Syntax
35+
<statement> {-and | -or | -xor} <statement>
36+
{! | -not} <statement>
37+
```
38+
39+
## Examples
40+
41+
The following example uses the `-and` and `-or` operators to connect three
42+
conditional statements. The result is TRUE only when the value of `$a` is
43+
greater than the value of `$b`, and either `$a` or `$b` is less than `20`.
2444

2545
```powershell
2646
($a -gt $b) -and (($a -lt 20) -or ($b -lt 20))
@@ -46,38 +66,29 @@ PowerShell supports the following logical operators.
4666
(1 -eq 1) -xor (2 -eq 2) # Result is False
4767
```
4868

49-
- Logical not (`-not`) or (`!`) - Negates the statement that follows.
69+
- Logical NOT (`-not`) or (`!`) - Negates the statement that follows.
5070

5171
```powershell
5272
-not (1 -eq 1) # Result is False
5373
!(1 -eq 1) # Result is False
5474
```
5575

56-
The previous examples also use the equal to comparison operator `-eq`. For more
57-
information, see [about_Comparison_Operators](about_Comparison_Operators.md).
58-
The examples also use the Boolean values of integers. The integer 0 has a value
59-
of FALSE. All other integers have a value of TRUE.
60-
61-
The syntax of the logical operators is as follows:
62-
63-
```Syntax
64-
<statement> {-and | -or | -xor} <statement>
65-
{! | -not} <statement>
66-
```
67-
68-
Statements that use the logical operators return Boolean (TRUE or FALSE)
69-
values.
70-
71-
The PowerShell logical operators evaluate only the statements required to
72-
determine the truth value of the statement. If the left operand in a statement
73-
that contains the and operator is FALSE, the right operand isn't evaluated. If
74-
the left operand in a statement that contains the or statement is TRUE, the
75-
right operand isn't evaluated. As a result, you can use these statements in
76-
the same way that you would use the `if` statement.
76+
The previous examples also use the equality comparison operator, `-eq`. For
77+
more information, see [about_Comparison_Operators][03]. The examples also use
78+
the boolean values of integers. The integer `0` has a boolean value of FALSE.
79+
All other integers have a value of TRUE.
7780

7881
## See also
7982

80-
- [about_Operators](about_Operators.md)
81-
- [about_Comparison_operators](about_Comparison_Operators.md)
82-
- [about_If](about_If.md)
83-
- [Compare-Object](xref:Microsoft.PowerShell.Utility.Compare-Object)
83+
- [about_Operators][02]
84+
- [about_Operator_Precedence][01]
85+
- [about_Comparison_Operators][03]
86+
- [about_If][04]
87+
- [Compare-Object][05]
88+
89+
<!-- link references -->
90+
[01]: about_Operator_Precedence.md
91+
[02]: about_Operators.md
92+
[03]: about_Comparison_Operators.md
93+
[04]: about_If.md
94+
[05]: xref:Microsoft.PowerShell.Utility.Compare-Object
Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Describes the operators that connect statements in PowerShell.
33
Locale: en-US
4-
ms.date: 08/29/2022
4+
ms.date: 12/30/2025
55
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_logical_operators?view=powershell-7.6&WT.mc_id=ps-gethelp
66
schema: 2.0.0
77
title: about_Logical_Operators
@@ -17,10 +17,30 @@ Describes the operators that connect statements in PowerShell.
1717
The PowerShell logical operators connect expressions and statements, allowing
1818
you to use a single expression to test for multiple conditions.
1919

20-
For example, the following statement uses the and operator and the or operator
21-
to connect three conditional statements. The statement is true only when the
22-
value of $a is greater than the value of $b, and either $a or $b is less than
23-
20.
20+
Statements that use the logical operators return boolean (TRUE or FALSE)
21+
values.
22+
23+
The PowerShell logical operators evaluate only the statements required to
24+
determine the truth value of the statement. If the left operand in a statement
25+
that contains the `-and` operator is FALSE, the right operand isn't evaluated.
26+
If the left operand in a statement that contains the `-or` statement is TRUE,
27+
the right operand isn't evaluated. As a result, you can use these statements in
28+
the same way that you would use the `if` statement.
29+
30+
## Syntax
31+
32+
The syntax of the logical operators is as follows:
33+
34+
```Syntax
35+
<statement> {-and | -or | -xor} <statement>
36+
{! | -not} <statement>
37+
```
38+
39+
## Examples
40+
41+
The following example uses the `-and` and `-or` operators to connect three
42+
conditional statements. The result is TRUE only when the value of `$a` is
43+
greater than the value of `$b`, and either `$a` or `$b` is less than `20`.
2444

2545
```powershell
2646
($a -gt $b) -and (($a -lt 20) -or ($b -lt 20))
@@ -46,38 +66,29 @@ PowerShell supports the following logical operators.
4666
(1 -eq 1) -xor (2 -eq 2) # Result is False
4767
```
4868

49-
- Logical not (`-not`) or (`!`) - Negates the statement that follows.
69+
- Logical NOT (`-not`) or (`!`) - Negates the statement that follows.
5070

5171
```powershell
5272
-not (1 -eq 1) # Result is False
5373
!(1 -eq 1) # Result is False
5474
```
5575

56-
The previous examples also use the equal to comparison operator `-eq`. For more
57-
information, see [about_Comparison_Operators](about_Comparison_Operators.md).
58-
The examples also use the Boolean values of integers. The integer 0 has a value
59-
of FALSE. All other integers have a value of TRUE.
60-
61-
The syntax of the logical operators is as follows:
62-
63-
```Syntax
64-
<statement> {-and | -or | -xor} <statement>
65-
{! | -not} <statement>
66-
```
67-
68-
Statements that use the logical operators return Boolean (TRUE or FALSE)
69-
values.
70-
71-
The PowerShell logical operators evaluate only the statements required to
72-
determine the truth value of the statement. If the left operand in a statement
73-
that contains the and operator is FALSE, the right operand isn't evaluated. If
74-
the left operand in a statement that contains the or statement is TRUE, the
75-
right operand isn't evaluated. As a result, you can use these statements in
76-
the same way that you would use the `if` statement.
76+
The previous examples also use the equality comparison operator, `-eq`. For
77+
more information, see [about_Comparison_Operators][03]. The examples also use
78+
the boolean values of integers. The integer `0` has a boolean value of FALSE.
79+
All other integers have a value of TRUE.
7780

7881
## See also
7982

80-
- [about_Operators](about_Operators.md)
81-
- [about_Comparison_operators](about_Comparison_Operators.md)
82-
- [about_If](about_If.md)
83-
- [Compare-Object](xref:Microsoft.PowerShell.Utility.Compare-Object)
83+
- [about_Operators][02]
84+
- [about_Operator_Precedence][01]
85+
- [about_Comparison_Operators][03]
86+
- [about_If][04]
87+
- [Compare-Object][05]
88+
89+
<!-- link references -->
90+
[01]: about_Operator_Precedence.md
91+
[02]: about_Operators.md
92+
[03]: about_Comparison_Operators.md
93+
[04]: about_If.md
94+
[05]: xref:Microsoft.PowerShell.Utility.Compare-Object

0 commit comments

Comments
 (0)