22external help file : System.Management.Automation.dll-Help.xml
33Locale : en-US
44Module Name : Microsoft.PowerShell.Core
5- ms.date : 04/26/2024
5+ ms.date : 04/23/2025
66online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.core/where-object?view=powershell-7.5&WT.mc_id=ps-gethelp
77schema : 2.0.0
88title : Where-Object
@@ -248,32 +248,41 @@ particular version of Windows.
248248Starting in Windows PowerShell 3.0, there are two different ways to construct a ` Where-Object `
249249command.
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
258- ` Get-Process | Where-Object {$_.PriorityClass -eq "Normal"} `
258+ ``` powershell
259+ Get-Process | Where-Object {$_.PriorityClass -eq "Normal"}
260+ ```
259261
260262 All PowerShell comparison operators are valid in the script block format. For more information,
261- see [ about_Comparison_Operators] ( About/about_Comparison_Operators.md ) .
263+ see [ about_Comparison_Operators] ( ./ About/about_Comparison_Operators.md) .
262264
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.
265+ - ** Simplified syntax** . To enable the simiplified syntax, ` Where-Object ` includes 31 swicth
266+ parameters that represent the comparison operators. The simplified syntax is easier to read and
267+ write than the script block syntax. You can combine one of the switch parameters with the
268+ ** Property** and ** Value** parameters to create a command that filters objects based on the values of
269+ their properties.
265270
266271 For example, the following commands also get processes that have a priority class of ` Normal ` .
267272 These commands are equivalent and you can use them interchangeably.
268273
269- ` Get-Process | Where-Object -Property PriorityClass -EQ -Value "Normal" `
274+ ``` powershell
275+ Get-Process | Where-Object -Property PriorityClass -Value Normal -EQ
276+ Get-Process | Where-Object PriorityClass -EQ Normal
277+ ```
270278
271- ` Get-Process | Where-Object PriorityClass -EQ "Normal" `
279+ As shown in the example, the parameter names ** Property** and ** Value** are optional. The
280+ ** Property** parameter is a positional parameter mapped to position ` 0 ` . The ** Value** parameter
281+ is a positional parameter mapped to position ` 1 ` . The switch parameter, used to specify the
282+ comparison, can be used in any position.
272283
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.
284+ The simplfied syntax was introduced in Windows PowerShell 3.0. For more information, see
285+ [ about_Simplified_Syntax] ( About/about_Simplified_Syntax.md ) .
277286
278287When you provide a single ** Property** to ` Where-Object ` , the cmdlet treats the value of the
279288property as a boolean expression. When the value of the property's ** Length** isn't zero, the
@@ -285,7 +294,7 @@ The previous example is functionally equivalent to:
285294- ` ('hi', '', 'there') | Where-Object { $_.Length -gt 0 } `
286295
287296For more information about how PowerShell evaluates booleans, see
288- [ about_Booleans] ( About /about_Booleans.md) .
297+ [ about_Booleans] ( about /about_Booleans.md) .
289298
290299## EXAMPLES
291300
@@ -400,9 +409,9 @@ The example uses the script block command format. Logical operators, such as `-a
400409` Where-Object ` command.
401410
402411- For more information about PowerShell logical operators, see
403- [ about_Logical_Operators] ( About/about_Logical_Operators .md ) .
412+ [ about_Logical_Operators] ( ./ About/about_logical_operators .md) .
404413- For more information about the Updatable Help feature, see
405- [ about_Updatable_Help] ( About/about_Updatable_Help.md ) .
414+ [ about_Updatable_Help] ( ./ About/about_Updatable_Help.md) .
406415
407416## PARAMETERS
408417
@@ -1188,7 +1197,7 @@ PowerShell includes the following aliases for `Where-Object`:
11881197Starting in Windows PowerShell 4.0, `Where` and `ForEach` methods were added for use with
11891198collections.
11901199
1191- You can read more about these methods here [about_Arrays](About/about_Arrays.md)
1200+ You can read more about these methods here [about_Arrays](./ About/about_Arrays.md)
11921201
11931202# # RELATED LINKS
11941203
@@ -1208,4 +1217,4 @@ You can read more about these methods here [about_Arrays](About/about_Arrays.md)
12081217
12091218[Tee-Object](../Microsoft.PowerShell.Utility/Tee-Object.md)
12101219
1211- [about_Booleans](About/about_Booleans.md)
1220+ [about_Booleans](./ About/about_Booleans.md)
0 commit comments