CmdID

CmdID / PowerShell / Cmdlets / Where

Where-Object

Selects objects from a collection based on their property values. PowerShell reference

From the PowerShell reference 34 parameters Aliases ?, where

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Selects objects from a collection based on their property values. The Where-Object cmdlet selects objects that have particular property values from the collection of objects that are passed to it. For example, you can use the Where-Object cmdlet to select files that were created after a certain date, events with a particular ID, or computers that use a particular version of Windows. Starting in Windows PowerShell 3.0, there are two different ways to construct a Where-Object command. - Scriptblock syntax. You can use a scriptblock to specify the property name, a comparison operator, and a property value. Where-Object returns all objects for which the scriptblock statement is true. For example, the following command gets processes where the value of the PriorityClass property equals Normal. Get-Process | Where-Object {$_.PriorityClass -eq "Normal"} All PowerShell comparison operators are valid in the scriptblock format. For more information, see about_Comparison_Operators. - Simplified syntax. To enable the simplified syntax, Where-Object includes 31 switch parameters that represent the comparison operators. The simplified syntax is easier to read and write than the scriptblock syntax. You can combine one of the switch parameters with the Property and Value parameters to create a command that filters objects based on the values of their properties. For example, the following commands also get processes that have a priority class of Normal. These commands are equivalent and you can use them interchangeably. Get-Process | Where-Object -Property PriorityClass -Value Normal -EQ Get-Process | Where-Object PriorityClass -EQ Normal As shown in the example, the parameter names Property and Value are optional. The Property parameter is a positional parameter mapped to position 0. The Value parameter is a positional parameter mapped to position 1. The switch parameter, used to specify the comparison, can be used in any position. The simplified syntax was introduced in Windows PowerShell 3.0. For more information, see about_Simplified_Syntax. When you provide a single Property to Where-Object, the cmdlet treats the value of the property as a boolean expression. When the value of the property's Length isn't zero, the expression evaluates to $true. For example: ('hi', '', 'there') | Where-Object Length The previous example is functionally equivalent to: …

Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] [-EQ] [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-FilterScript] <ScriptBlock> [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -Match [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CEQ [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -NE [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CNE [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -GT [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CGT [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -LT [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CLT [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -GE [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CGE [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -LE [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CLE [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -Like [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CLike [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -NotLike [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CNotLike [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CMatch [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -NotMatch [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CNotMatch [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -Contains [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CContains [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -NotContains [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CNotContains [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -In [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CIn [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -NotIn [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -CNotIn [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -Is [<CommonParameters>]
Where-Object [-InputObject <PSObject>] [-Property] <String> [[-Value] <Object>] -IsNot [<CommonParameters>]

Get stopped services

Get-Service | Where-Object { $_.Status -eq "Stopped" } Get-Service | Where-Object Status -EQ "Stopped"Identify

Get processes based on working set

Get-Process | Where-Object { $_.WorkingSet -gt 250MB } Get-Process | Where-Object WorkingSet -GT 250MBIdentify

Get processes based on process name

Get-Process | Where-Object { $_.ProcessName -match "^p.*" } Get-Process | Where-Object ProcessName -Match "^p.*"Identify

Use the comparison statement format

Get-Process | Where-Object -Property Handles -GE -Value 1000 Get-Process | where Handles -GE 1000Identify

Get commands based on properties

# Use Where-Object to get commands that have any value for the OutputType # property of the command. This omits commands that do not have an OutputType # property and those that have an OutputType property, but no property value. Get-Command | Where-Object OutputType Get-Command | Where-Object { $_.OutputType }Identify

Use multiple conditions

Get-Module -ListAvailable | Where-Object { ($_.Name -notlike "Microsoft*" -and $_.Name -notlike "PS*") -and $_.HelpInfoUri }Identify

Its page in the reference: Where-Object.

Parameters

34 in the PowerShell reference
Show its 34 parameters
-CContainsIndicates that this cmdlet gets objects from a collection if the property value of the object is an exact match for the specified value. This operation is case-sensitive. For example: Get-Process | Where-Object ProcessName -CContains "svchost" CContains refers to a collection of values and is true if the collection contains an item that is an exact match for the specified value. If the input is a single object, PowerShell converts it to a collection of one object. This parameter was introduced in Windows PowerShell 3.0.
-CEQIndicates that this cmdlet gets objects if the property value is the same as the specified value. This operation is case-sensitive. This parameter was introduced in Windows PowerShell 3.0.
-CGEIndicates that this cmdlet gets objects if the property value is greater than or equal to the specified value. This operation is case-sensitive. This parameter was introduced in Windows PowerShell 3.0.
-CGTIndicates that this cmdlet gets objects if the property value is greater than the specified value. This operation is case-sensitive. This parameter was introduced in Windows PowerShell 3.0.
-CInIndicates that this cmdlet gets objects if the property value includes the specified value. This operation is case-sensitive. For example: Get-Process | Where-Object -Value "svchost" -CIn ProcessName CIn resembles CContains, except that the property and value positions are reversed. For example, the following statements are both true. "abc", "def" -CContains "abc" "abc" -CIn "abc", "def" This parameter was introduced in Windows PowerShell 3.0.
-CLEIndicates that this cmdlet gets objects if the property value is less-than or equal to the specified value. This operation is case-sensitive. This parameter was introduced in Windows PowerShell 3.0.
-CLikeIndicates that this cmdlet gets objects if the property value matches a value that includes wildcard characters (*). This operation is case-sensitive. For example: Get-Process | Where-Object ProcessName -CLike "*host" This parameter was introduced in Windows PowerShell 3.0.
-CLTIndicates that this cmdlet gets objects if the property value is less-than the specified value. This operation is case-sensitive. This parameter was introduced in Windows PowerShell 3.0.
-CMatchIndicates that this cmdlet gets objects if the property value matches the specified regular expression. This operation is case-sensitive. When the input is a single object, the matched value is saved in the $Matches automatic variable. For example: Get-Process | Where-Object ProcessName -CMatch "Shell" This parameter was introduced in Windows PowerShell 3.0.
-CNEIndicates that this cmdlet gets objects if the property value is different than the specified value. This operation is case-sensitive. This parameter was introduced in Windows PowerShell 3.0.
-CNotContainsIndicates that this cmdlet gets objects if the property value of the object isn't an exact match for the specified value. This operation is case-sensitive. For example: Get-Process | Where-Object ProcessName -CNotContains "svchost" NotContains and CNotContains refer to a collection of values and are true when the collection doesn't contain any items that are an exact match for the specified value. If the input is a single object, PowerShell converts it to a collection of one object. This parameter was introduced in Windows PowerShell 3.0.
-CNotInIndicates that this cmdlet gets objects if the property value isn't an exact match for the specified value. This operation is case-sensitive. For example: Get-Process | Where-Object -Value "svchost" -CNotIn -Property ProcessName NotIn and CNotIn operators resemble NotContains and CNotContains, except that the property and value positions are reversed. For example, the following statements are true. "abc", "def" -CNotContains "Abc" "abc" -CNotIn "Abc", "def"
-CNotLikeIndicates that this cmdlet gets objects if the property value doesn't match a value that includes wildcard characters. This operation is case-sensitive. For example: Get-Process | Where-Object ProcessName -CNotLike "*host" This parameter was introduced in Windows PowerShell 3.0.
-CNotMatchIndicates that this cmdlet gets objects if the property value doesn't match the specified regular expression. This operation is case-sensitive. When the input is a single object, the matched value is saved in the $Matches automatic variable. For example: Get-Process | Where-Object ProcessName -CNotMatch "Shell" This parameter was introduced in Windows PowerShell 3.0.
-ContainsIndicates that this cmdlet gets objects if any item in the property value of the object is an exact match for the specified value. For example: Get-Process | Where-Object ProcessName -Contains "Svchost" If the input is a single object, PowerShell converts it to a collection of one object. This parameter was introduced in Windows PowerShell 3.0.
-EQIndicates that this cmdlet gets objects if the property value is the same as the specified value. This parameter was introduced in Windows PowerShell 3.0.
-FilterScriptSpecifies the scriptblock that's used to filter the objects. Enclose the scriptblock in braces ({}). The parameter name, FilterScript, is optional.
-GEIndicates that this cmdlet gets objects if the property value is greater than or equal to the specified value. This parameter was introduced in Windows PowerShell 3.0.
-GTIndicates that this cmdlet gets objects if the property value is greater than the specified value. This parameter was introduced in Windows PowerShell 3.0.
-InIndicates that this cmdlet gets objects if the property value matches any of the specified values. For example: Get-Process | Where-Object -Property ProcessName -In -Value "Svchost", "TaskHost", "WsmProvHost" If the input is a single object, PowerShell converts it to a collection of one object. If the property value of an object is an array, PowerShell uses reference equality to determine a match. Where-Object returns the object only if the value of the Property parameter and any value of Value are the same instance of an object. This parameter was introduced in Windows PowerShell 3.0.
-InputObjectSpecifies the objects to filter. You can also pipe the objects to Where-Object. When you use the InputObject parameter with Where-Object, instead of piping command results to Where-Object, the cmdlet treats the InputObject as a single object. This is true even if the value is a collection that's the result of a command, such as -InputObject (Get-Process). Because InputObject can't return individual properties from an array or collection of objects, we recommend that, if you use Where-Object to filter a collection of objects for those objects that have specific values in defined properties, you use Where-Object in the pipeline, as shown in the examples in this topic.
-IsIndicates that this cmdlet gets objects if the property value is an instance of the specified .NET type. Enclose the type name in square brackets. For example, Get-Process | Where-Object StartTime -Is [datetime] This parameter was introduced in Windows PowerShell 3.0.
-IsNotIndicates that this cmdlet gets objects if the property value isn't an instance of the specified .NET type. For example, Get-Process | where StartTime -IsNot [datetime] This parameter was introduced in Windows PowerShell 3.0.
-LEIndicates that this cmdlet gets objects if the property value is less than or equal to the specified value. This parameter was introduced in Windows PowerShell 3.0.
-LikeIndicates that this cmdlet gets objects if the property value matches a value that includes wildcard characters (*). For example: Get-Process | Where-Object ProcessName -Like "*host" This parameter was introduced in Windows PowerShell 3.0.
-LTIndicates that this cmdlet gets objects if the property value is less than the specified value. This parameter was introduced in Windows PowerShell 3.0.
-MatchIndicates that this cmdlet gets objects if the property value matches the specified regular expression. When the input is a single object, the matched value is saved in the $Matches automatic variable. For example: Get-Process | Where-Object ProcessName -Match "shell" This parameter was introduced in Windows PowerShell 3.0.
-NEIndicates that this cmdlet gets objects if the property value is different than the specified value. This parameter was introduced in Windows PowerShell 3.0.
-NotContainsIndicates that this cmdlet gets objects if none of the items in the property value is an exact match for the specified value. For example: Get-Process | Where-Object ProcessName -NotContains "Svchost" NotContains refers to a collection of values and is true if the collection doesn't contain any items that are an exact match for the specified value. If the input is a single object, PowerShell converts it to a collection of one object. This parameter was introduced in Windows PowerShell 3.0.
-NotInIndicates that this cmdlet gets objects if the property value isn't an exact match for any of the specified values. For example: Get-Process | Where-Object -Value "svchost" -NotIn -Property ProcessName If the value of Value is a single object, PowerShell converts it to a collection of one object. If the property value of an object is an array, PowerShell uses reference equality to determine a match. Where-Object returns the object only if the value of Property and any value of Value aren't the same instance of an object. This parameter was introduced in Windows PowerShell 3.0.
-NotLikeIndicates that this cmdlet gets objects if the property value doesn't match a value that includes wildcard characters (*). For example: Get-Process | Where-Object ProcessName -NotLike "*host" This parameter was introduced in Windows PowerShell 3.0.
-NotMatchIndicates that this cmdlet gets objects when the property value doesn't match the specified regular expression. When the input is a single object, the matched value is saved in the $Matches automatic variable. For example: Get-Process | Where-Object ProcessName -NotMatch "powershell" This parameter was introduced in Windows PowerShell 3.0.
-PropertySpecifies the name of a property of the input object. The property must be an instance property, not a static property. This is a positional parameter, so the name, Property, is optional. This parameter was introduced in Windows PowerShell 3.0.
-ValueSpecifies a property value. The parameter name, Value, is optional. This parameter accepts wildcard characters when used with the following comparison parameters: - CLike - CNotLike - Like - NotLike This parameter was introduced in Windows PowerShell 3.0.