C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
PowerShell Where-ObjectThe Where-Object in PowerShell selects the objects from a collection based on their property values. With the Starting of PowerShell version 3.0, you can construct the Where-Object cmdlet in the following two different ways:
SyntaxWhere-Object [-Property] <string> [[-Value] <Object>] [-InputObject <psobject>] [-EQ] [<CommonParameters>] Where-Object [-FilterScript] <scriptblock> [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -Match [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -CEQ [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -NE [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -CNE [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -GT [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -CGT [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -LT [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -CLT [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -GE [-InputObject <psobject>] [<CommonParameters>] </textarea></div> <br> <div class="codeblock"><textarea name="code" class="xml"> Where-Object [-Property] <string> [[-Value] <Object>] -CGE [-InputObject <psobject>] [<CommonParameters>] </textarea></div> <br> <div class="codeblock"><textarea name="code" class="xml"> Where-Object [-Property] <string> [[-Value] <Object>] -LE [-InputObject <psobject>] [<CommonParameters>] </textarea></div> <br> <div class="codeblock"><textarea name="code" class="xml"> Where-Object [-Property] <string> [[-Value] <Object>] -CLE [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -Like [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -CLike [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -NotLike [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -CNotLike [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -CMatch [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -NotMatch [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -CNotMatch [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -Contains [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -CContains [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -NotContains [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -CNotContains [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -In [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -CIn [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -NotIn [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -CNotIn [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -Is [-InputObject <psobject>] [<CommonParameters>] Where-Object [-Property] <string> [[-Value] <Object>] -IsNot [-InputObject <psobject>] [<CommonParameters>] ParametersFollowing are the parameters used in this cmdlet: -Property This parameter is used to specify the name of an object property. It is optional and was introduced in the 3.0 version of Windows PowerShell. -Value This parameter is used to specify the value of a property. It accepts the wildcard (*) characters when used with the comparison parameters. It was also introduced in version 3.0 of PowerShell. -InputObject This parameter is used to specify those objects which are to be filtered. We can also pipe the objects to the Where-Object cmdlet. -EQ The Where-Object cmdlet used this parameter to get the objects if the value of the property is the same as the specified value. -FilterScript This parameter is used to specify the block of a script for filtering the objects. You must enclose the script block in the braces {}. -Match The Where-Object cmdlet used this parameter to get the objects if the value of the property matches the given regular expression. -CEQ The Where-Object cmdlet used this parameter to get the objects if the value of the property is the same as the specified value. -NE The Where-Object cmdlet used this parameter to get the objects if the value of the property is different from the specified value. -CNE The Where-Object cmdlet used this parameter to get the objects if the value of the property is different from the specified value. This operation is case-sensitive. -GT The Where-Object cmdlet used this parameter to get the objects if the value of the property is greater than the given value. -CGT The Where-Object cmdlet used this parameter to get the objects if the value of the property is greater than the given value. This operation is case-sensitive. -LT The Where-Object cmdlet used this parameter to get the objects if the value of the property is less than the given value. -CLT The Where-Object cmdlet used this parameter to get the objects if the value of the property is less than the given value. This operation is case-sensitive. -GE The Where-Object cmdlet used this parameter to get the objects if the value of the property is greater than or equal to the given value. -CGE The Where-Object cmdlet used this parameter to get the objects if the value of the property is greater than or equal to the given value. This operation is case-sensitive. -LE The Where-Object cmdlet used this parameter to get the objects if the value of the property is less than or equal to the given value. -CLE The Where-Object cmdlet used this parameter to get the objects if the value of the property is less than or equal to the given value. This operation is case-sensitive. -Like The Where-Object cmdlet used this parameter to get the objects if the value of the property matches a value which includes the wildcard characters. -CLike The Where-Object cmdlet used this parameter to get the objects if the value of the property matches a value which includes the wildcard characters. This operation is case-sensitive. -NotLike The Where-Object cmdlet used this parameter to get the objects if the value of the property does not match a value, which includes the wildcard characters. -CNotLike The Where-Object cmdlet used this parameter to get the objects if the value of the property does not match a value, which includes the wildcard characters. This operation is case-sensitive. -CMatch The Where-Object cmdlet used this parameter to get the objects if the value of the property matches the given regular expression. This operation is case-sensitive -NotMatch The Where-Object cmdlet used this parameter to get the objects if the value of the property does not match the given regular expression. If the input is scalar, the value which is matched is saved or stored in the $Matches automatic variable. -CNotMatch The Where-Object cmdlet used this parameter to get the objects if the value of the property does not match with the given regular expression. This operation is case-sensitive. -Contains The Where-Object cmdlet used this parameter to get the objects from the collection if the property value of an object matches with the given value. -CContains The Where-Object cmdlet used this parameter to get the objects if the item in the property value of an object matches with the given value. This operation is case-sensitive. -NotContains The Where-Object cmdlet used this parameter to get the objects if none of the items in the property value of an object matches with the given value. -CNotContains The Where-Object cmdlet used this parameter to get the objects if an item in the property value of an object does not match with the given value. This operation is case-sensitive. -In The Where-Object cmdlet used this parameter to get the objects if the value of the property matches any of the given values. -CIn The Where-Object cmdlet used this parameter to get the objects if the value of the property matches any of the given values. This operation is case-sensitive. -NotIn The Where-Object cmdlet used this parameter to get the objects if the value of the property does not match any of the given values. -CNotIn The Where-Object cmdlet used this parameter to get the objects if the value of the property does not match any of the given values. This operation is case-sensitive. -Is The Where-Object cmdlet used this parameter to get the objects if the value of the property is an instance of a given .NET Framework type. You must enclose the name of the type in square brackets. -IsNot The Where-Object cmdlet used this parameter to get the objects if the value of the property is not an instance of a given .NET Framework type. ExamplesExample 1: Get the stopped Services Both the commands in this example get a list of all the services which are currently stopped. The first command uses the format of a script block, and the second command uses the format of a comparison statement. Example 2: Get the processes on the basis of the process name The command in this example gets the name of services that start with the A letter. The -Match parameter allows you to use a regular expression.
Next TopicPowerShell Variables
|