PowerShell Logo Small

Where-Object



This is the built-in help made by Microsoft for the command 'Where-Object', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Creates a filter that controls which objects will be passed along a command pipeline.

SYNTAX


Where-Object [-FilterScript] <scriptblock> [-InputObject <psobject>] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Where-Object cmdlet selects objects from the set of objects that are passed to it. It uses a script block as a filter and evaluates the scrip
t block for each object. If the result of the evaluation is True, the object is returned. If the result of the evaluation is not True, the object
is ignored.



<

RELATED LINKS


Online version: http://go.microsoft.com/fwlink/?LinkID=113423

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>get-service | where-object {$_.Status -eq "Stopped"}



Description
-----------
This command gets a list of all services that are currently stopped. The "$" symbol represents each object that is passed to the Where-Object cmd
let.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>get-process | where-object {$_.workingset -gt 25000*1024}



Description
-----------
This command lists processes that have a working set greater than 25,000 kilobytes (KB). Because the value of the WorkingSet property is stored i
n bytes, the value of 25,000 is multiplied by 1,024.








-------------------------- EXAMPLE 3 --------------------------

C:\PS>get-process | where-object { $_.ProcessName -match "^p.*" }



Description
-----------
This command gets the processes with a ProcessName property that begins with the letter "p". The match operator enables you to use regular expres
sions within a Where clause.








-------------------------- EXAMPLE 4 --------------------------

C:\PS>get-process -name svchost | where-object {$True}



Description
-----------
This command lists all of the processes named "svchost".

The Where-Object cmdlet evaluates the script block, which typically includes a reference to the object currently in the pipeline ($_), and casts
the results to a Boolean type: True or False. If the result is True, the object is returned. Otherwise, it is discarded.

In this case, the script block just returns True, so all the objects are returned.