We can use the cmdlet Where-Object to filter data returned by other cmdlets. The below command filter the result form Get-Process command and select processes which name is equal to “svchost”.
Get-Process | Where-Object {$_.Name -eq "svchost"}
The below command looking for processes where handles were greater than or equal to 200
Get-Process | Where-Object {$_.handles -ge 200}
You can also use the -and and -or parameters.
Get-Process | Where-Object {$_.handles -gt 200 -and $_.name -eq "svchost"}
You can also filter by Boolean value (True/False).
Get-Service | Where-Object {$_.CanStop}
Get-Service | Where-Object { -not $_.CanStop}
Other useful conditional operators are:
-lt — Less than
-le — Less than or equal to
-gt — Greater than
-ge — Greater than or equal to
-eq — Equal to
-ne — Not equal to
-like — Like; uses wildcards for pattern matching
Advertisement