TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

PowerShell Where-Object

PowerShell Where-Object with What is PowerShell, History of PowerShell, Features of PowerShell, PowerShell vs CMD, PowerShell Scripting, PowerShell Versions, PowerShell Commands, PowerShell Looping, PowerShell Conditions, PowerShell Array, PowerShell Brackets etc.

<< Back to POWERSHELL

PowerShell Where-Object

The 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:

  1. Comparison Statement: With the Starting of PowerShell 3.0, we can add the comparison operators as the parameters in the Where-Object command.
  2. Script Block: We can use the script block to specify the name and value of the property and a comparison operator. The Where-Object cmdlet returns all the objects for which the statement of script block is true.

Syntax

Where-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>]

Parameters

Following 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.

Examples

Example 1: Get the stopped Services

PowerShell Where-Object PowerShell Where-Object

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

PowerShell Where-Object

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.






Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf