Contact Info

Crumbtrail

ActiveXperts.com » Administration » Powershell » Powershell 3.0 » Where-Object

Where-Object - Powershell 3.0 CmdLet

ActiveXperts Network Monitor ships with integrated Powershell scripts to monitor complex network. The scripts run out of the box
Download the ActiveXperts Network Monitor FREE version now »

Where-Object

Short description
Selects objects from a collection based on their property values.

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





Description
The Where-Object cmdlet selects objects that have particular property values from the collection of objects that are pa
ssed to it. For example you can use the Where-Object cmdlet to select files that were created after a certain date, eve
nts with a particular ID, or computers with a particular version of Windows.


Beginning in Windows PowerShell 3.0, there are two different ways to construct a  Where-Object command.


Script block. You can use a script block to specify the property name, a comparison operator, and a property value. Whe
re-Object returns all objects for which the script block statement is true.


For example, the following command gets processes in the Normal priority class, that is, processes where the value of t
he PriorityClass property equals "Normal".


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


All Windows PowerShell comparison operators are valid in the script block format. For more information about comparison
 operators, see about_Comparison_Operators (http://go.microsoft.com/fwlink/?LinkID=113217).


Comparison statement. You can also write a comparison statement, which is much more like natural language. Comparison s
tatements were introduced in Windows PowerShell 3.0.


For example, the following commands also get processes that have a priority class of "Normal". These commands are equiv
alent and can be used interchangeably.


Get-Process | Where-Object -Property PriorityClass -eq -Value "Normal"


Get-Process | Where-Object PriorityClass -eq "Normal"


Beginning in Windows PowerShell 3.0, Where-Object adds comparison operators as parameters in a Where-Object command. Un
less specified, all operators are case-insensitive. Prior to Windows PowerShell 3.0, the comparison operators in the Wi
ndows PowerShell language could be used only in script blocks.