Skip to content

Commit fe785b5

Browse files
Fixes #12009 - Standardize terminology around "simplified syntax" (#12021)
* Standardize terminology around "simplified syntax" * Fix build error * Apply suggestions from review --------- Co-authored-by: Mikey Lombardi (He/Him) <[email protected]>
1 parent f3a9fee commit fe785b5

File tree

8 files changed

+125
-85
lines changed

8 files changed

+125
-85
lines changed

reference/5.1/Microsoft.PowerShell.Core/ForEach-Object.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: System.Management.Automation.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Core
5-
ms.date: 04/26/2024
5+
ms.date: 04/23/2025
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-5.1&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: ForEach-Object
@@ -36,7 +36,7 @@ input objects can be piped to the cmdlet or specified using the **InputObject**
3636
Starting in Windows PowerShell 3.0, there are two different ways to construct a `ForEach-Object`
3737
command.
3838

39-
- **Script block**. You can use a script block to specify the operation. Within the script block,
39+
- **Script block syntax**. You can use a script block to specify the operation. Within the script block,
4040
use the `$_` variable to represent the current object. The script block is the value of the
4141
**Process** parameter. The script block can contain any PowerShell script.
4242

@@ -52,15 +52,18 @@ command.
5252
> The script blocks run in the caller's scope. Therefore, the blocks have access to variables in
5353
> that scope and can create new variables that persist in that scope after the cmdlet completes.
5454
55-
- **Operation statement**. You can also write an operation statement, which is much more like
56-
natural language. You can use the operation statement to specify a property value or call a
57-
method. Operation statements were introduced in Windows PowerShell 3.0.
55+
- **Simplified syntax**. Using the simplified syntax, you specify a property or method name of the
56+
object in the pipeline. `ForEach-Object` returns the value of the property or method for each
57+
object in the pipeline.
5858

5959
For example, the following command also gets the value of the **ProcessName** property of each
6060
process on the computer.
6161

6262
`Get-Process | ForEach-Object ProcessName`
6363

64+
The simplified syntax was introduced in Windows PowerShell 3.0. For more information, see
65+
[about_Simplified_Syntax](About/about_Simplified_Syntax.md).
66+
6467
## EXAMPLES
6568

6669
### Example 1: Divide integers in an array
@@ -82,8 +85,9 @@ This example takes an array of three integers and divides each one of them by 10
8285
This example processes the files and directories in the PowerShell installation directory `$PSHOME`.
8386

8487
```powershell
85-
Get-ChildItem $PSHOME |
86-
ForEach-Object -Process {if (!$_.PSIsContainer) {$_.Name; $_.Length / 1024; " " }}
88+
Get-ChildItem $PSHOME | ForEach-Object -Process {
89+
if (!$_.PSIsContainer) {$_.Name; $_.Length / 1024; " " }
90+
}
8791
```
8892

8993
If the object isn't a directory, the script block gets the name of the file, divides the value of

reference/5.1/Microsoft.PowerShell.Core/Where-Object.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: System.Management.Automation.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Core
5-
ms.date: 04/26/2024
5+
ms.date: 04/23/2025
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/where-object?view=powershell-5.1&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: Where-Object
@@ -241,32 +241,38 @@ particular version of Windows.
241241
Starting in Windows PowerShell 3.0, there are two different ways to construct a `Where-Object`
242242
command.
243243

244-
- **Script block**. You can use a script block to specify the property name, a comparison operator,
244+
- **Script block syntax**. You can use a script block to specify the property name, a comparison operator,
245245
and a property value. `Where-Object` returns all objects for which the script block statement is
246246
true.
247247

248-
For example, the following command gets processes in the `Normal` priority class, that is,
249-
processes where the value of the **PriorityClass** property equals `Normal`.
248+
For example, the following command gets processes where the value of the **PriorityClass**
249+
property equals `Normal`.
250250

251251
`Get-Process | Where-Object {$_.PriorityClass -eq "Normal"}`
252252

253253
All PowerShell comparison operators are valid in the script block format. For more information,
254254
see [about_Comparison_Operators](./About/about_Comparison_Operators.md).
255255

256-
- **Comparison statement**. You can also write a comparison statement, which is much more like
257-
natural language. Comparison statements were introduced in Windows PowerShell 3.0.
256+
- **Simplified syntax**. To enable the simiplified syntax, `Where-Object` includes 31 switch
257+
parameters that represent the comparison operators. The simplified syntax is easier to read and
258+
write than the script block syntax. You can combine one of the switch parameters with the
259+
**Property** and **Value** parameters to create a command that filters objects based on the
260+
values of their properties.
258261

259262
For example, the following commands also get processes that have a priority class of `Normal`.
260263
These commands are equivalent and you can use them interchangeably.
261264

262-
`Get-Process | Where-Object -Property PriorityClass -EQ -Value "Normal"`
265+
`Get-Process | Where-Object -Property PriorityClass -Value Normal -EQ`
263266

264-
`Get-Process | Where-Object PriorityClass -EQ "Normal"`
267+
`Get-Process | Where-Object PriorityClass -EQ Normal`
265268

266-
Starting in Windows PowerShell 3.0, `Where-Object` adds comparison operators as parameters in a
267-
`Where-Object` command. Unless specified, all operators are case-insensitive. Before Windows
268-
PowerShell 3.0, the comparison operators in the PowerShell language were only usable in script
269-
blocks.
269+
As shown in the example, the parameter names **Property** and **Value** are optional. The
270+
**Property** parameter is a positional parameter mapped to position `0`. The **Value** parameter
271+
is a positional parameter mapped to position `1`. The switch parameter, used to specify the
272+
comparison, can be used in any position.
273+
274+
The simplfied syntax was introduced in Windows PowerShell 3.0. For more information, see
275+
[about_Simplified_Syntax](About/about_Simplified_Syntax.md).
270276

271277
When you provide a single **Property** to `Where-Object`, the cmdlet treats the value of the
272278
property as a boolean expression. When the value of the property's **Length** isn't zero, the
@@ -1181,4 +1187,4 @@ You can read more about these methods here [about_Arrays](./About/about_Arrays.m
11811187

11821188
[Tee-Object](../Microsoft.PowerShell.Utility/Tee-Object.md)
11831189

1184-
[about_Booleans](about/about_Booleans.md)
1190+
[about_Booleans](./About/about_Booleans.md)

reference/7.4/Microsoft.PowerShell.Core/ForEach-Object.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: System.Management.Automation.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Core
5-
ms.date: 04/13/2025
5+
ms.date: 04/23/2025
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-7.4&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: ForEach-Object
@@ -45,7 +45,7 @@ input objects can be piped to the cmdlet or specified using the **InputObject**
4545
Starting in Windows PowerShell 3.0, there are two different ways to construct a `ForEach-Object`
4646
command.
4747

48-
- **Script block**. You can use a script block to specify the operation. Within the script block,
48+
- **Script block syntax**. You can use a script block to specify the operation. Within the script block,
4949
use the `$_` variable to represent the current object. The script block is the value of the
5050
**Process** parameter. The script block can contain any PowerShell script.
5151

@@ -61,15 +61,18 @@ command.
6161
> The script blocks run in the caller's scope. Therefore, the blocks have access to variables in
6262
> that scope and can create new variables that persist in that scope after the cmdlet completes.
6363
64-
- **Operation statement**. You can also write an operation statement, which is much more like
65-
natural language. You can use the operation statement to specify a property value or call a
66-
method. Operation statements were introduced in Windows PowerShell 3.0.
64+
- **Simplified syntax**. Using the simplified syntax, you specify a property or method name of the
65+
object in the pipeline. `ForEach-Object` returns the value of the property or method for each
66+
object in the pipeline.
6767

6868
For example, the following command also gets the value of the **ProcessName** property of each
6969
process on the computer.
7070

7171
`Get-Process | ForEach-Object ProcessName`
7272

73+
The simplified syntax was introduced in Windows PowerShell 3.0. For more information, see
74+
[about_Simplified_Syntax](About/about_Simplified_Syntax.md).
75+
7376
- **Parallel running script block**. Beginning with PowerShell 7.0, a third parameter set is
7477
available that runs each script block in parallel. The **ThrottleLimit** parameter limits the
7578
number of parallel scripts running at a time. As before, use the `$_` variable to represent the
@@ -109,8 +112,9 @@ This example takes an array of three integers and divides each one of them by 10
109112
This example processes the files and directories in the PowerShell installation directory `$PSHOME`.
110113

111114
```powershell
112-
Get-ChildItem $PSHOME |
113-
ForEach-Object -Process {if (!$_.PSIsContainer) {$_.Name; $_.Length / 1024; " " }}
115+
Get-ChildItem $PSHOME | ForEach-Object -Process {
116+
if (!$_.PSIsContainer) {$_.Name; $_.Length / 1024; " " }
117+
}
114118
```
115119

116120
If the object isn't a directory, the script block gets the name of the file, divides the value of

reference/7.4/Microsoft.PowerShell.Core/Where-Object.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: System.Management.Automation.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Core
5-
ms.date: 04/26/2024
5+
ms.date: 04/23/2025
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/where-object?view=powershell-7.4&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: Where-Object
@@ -248,32 +248,38 @@ particular version of Windows.
248248
Starting in Windows PowerShell 3.0, there are two different ways to construct a `Where-Object`
249249
command.
250250

251-
- **Script block**. You can use a script block to specify the property name, a comparison operator,
251+
- **Script block syntax**. You can use a script block to specify the property name, a comparison operator,
252252
and a property value. `Where-Object` returns all objects for which the script block statement is
253253
true.
254254

255-
For example, the following command gets processes in the `Normal` priority class, that is,
256-
processes where the value of the **PriorityClass** property equals `Normal`.
255+
For example, the following command gets processes where the value of the **PriorityClass**
256+
property equals `Normal`.
257257

258258
`Get-Process | Where-Object {$_.PriorityClass -eq "Normal"}`
259259

260260
All PowerShell comparison operators are valid in the script block format. For more information,
261261
see [about_Comparison_Operators](./About/about_Comparison_Operators.md).
262262

263-
- **Comparison statement**. You can also write a comparison statement, which is much more like
264-
natural language. Comparison statements were introduced in Windows PowerShell 3.0.
263+
- **Simplified syntax**. To enable the simiplified syntax, `Where-Object` includes 31 switch
264+
parameters that represent the comparison operators. The simplified syntax is easier to read and
265+
write than the script block syntax. You can combine one of the switch parameters with the
266+
**Property** and **Value** parameters to create a command that filters objects based on the
267+
values of their properties.
265268

266269
For example, the following commands also get processes that have a priority class of `Normal`.
267270
These commands are equivalent and you can use them interchangeably.
268271

269-
`Get-Process | Where-Object -Property PriorityClass -EQ -Value "Normal"`
272+
`Get-Process | Where-Object -Property PriorityClass -Value Normal -EQ`
270273

271-
`Get-Process | Where-Object PriorityClass -EQ "Normal"`
274+
`Get-Process | Where-Object PriorityClass -EQ Normal`
272275

273-
Starting in Windows PowerShell 3.0, `Where-Object` adds comparison operators as parameters in a
274-
`Where-Object` command. Unless specified, all operators are case-insensitive. Before Windows
275-
PowerShell 3.0, the comparison operators in the PowerShell language were only usable in script
276-
blocks.
276+
As shown in the example, the parameter names **Property** and **Value** are optional. The
277+
**Property** parameter is a positional parameter mapped to position `0`. The **Value** parameter
278+
is a positional parameter mapped to position `1`. The switch parameter, used to specify the
279+
comparison, can be used in any position.
280+
281+
The simplfied syntax was introduced in Windows PowerShell 3.0. For more information, see
282+
[about_Simplified_Syntax](About/about_Simplified_Syntax.md).
277283

278284
When you provide a single **Property** to `Where-Object`, the cmdlet treats the value of the
279285
property as a boolean expression. When the value of the property's **Length** isn't zero, the
@@ -1208,4 +1214,4 @@ You can read more about these methods here [about_Arrays](./About/about_Arrays.m
12081214

12091215
[Tee-Object](../Microsoft.PowerShell.Utility/Tee-Object.md)
12101216

1211-
[about_Booleans](about/about_Booleans.md)
1217+
[about_Booleans](./About/about_Booleans.md)

reference/7.5/Microsoft.PowerShell.Core/ForEach-Object.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: System.Management.Automation.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Core
5-
ms.date: 04/13/2025
5+
ms.date: 04/23/2025
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/foreach-object?view=powershell-7.5&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: ForEach-Object
@@ -45,7 +45,7 @@ input objects can be piped to the cmdlet or specified using the **InputObject**
4545
Starting in Windows PowerShell 3.0, there are two different ways to construct a `ForEach-Object`
4646
command.
4747

48-
- **Script block**. You can use a script block to specify the operation. Within the script block,
48+
- **Script block syntax**. You can use a script block to specify the operation. Within the script block,
4949
use the `$_` variable to represent the current object. The script block is the value of the
5050
**Process** parameter. The script block can contain any PowerShell script.
5151

@@ -61,15 +61,18 @@ command.
6161
> The script blocks run in the caller's scope. Therefore, the blocks have access to variables in
6262
> that scope and can create new variables that persist in that scope after the cmdlet completes.
6363
64-
- **Operation statement**. You can also write an operation statement, which is much more like
65-
natural language. You can use the operation statement to specify a property value or call a
66-
method. Operation statements were introduced in Windows PowerShell 3.0.
64+
- **Simplified syntax**. Using the simplified syntax, you specify a property or method name of the
65+
object in the pipeline. `ForEach-Object` returns the value of the property or method for each
66+
object in the pipeline.
6767

6868
For example, the following command also gets the value of the **ProcessName** property of each
6969
process on the computer.
7070

7171
`Get-Process | ForEach-Object ProcessName`
7272

73+
The simplified syntax was introduced in Windows PowerShell 3.0. For more information, see
74+
[about_Simplified_Syntax](About/about_Simplified_Syntax.md).
75+
7376
- **Parallel running script block**. Beginning with PowerShell 7.0, a third parameter set is
7477
available that runs each script block in parallel. The **ThrottleLimit** parameter limits the
7578
number of parallel scripts running at a time. As before, use the `$_` variable to represent the
@@ -109,8 +112,9 @@ This example takes an array of three integers and divides each one of them by 10
109112
This example processes the files and directories in the PowerShell installation directory `$PSHOME`.
110113

111114
```powershell
112-
Get-ChildItem $PSHOME |
113-
ForEach-Object -Process {if (!$_.PSIsContainer) {$_.Name; $_.Length / 1024; " " }}
115+
Get-ChildItem $PSHOME | ForEach-Object -Process {
116+
if (!$_.PSIsContainer) {$_.Name; $_.Length / 1024; " " }
117+
}
114118
```
115119

116120
If the object isn't a directory, the script block gets the name of the file, divides the value of

0 commit comments

Comments
 (0)