Combining more than one filter in where-object filtering in Powershell

A lot of time you want to filter your results from Get-* command in Powershell. One way to do will be to pass the results from Get-* command through two where-object pipe lines. Or you can take advantage of logical operators to combine more than one filter in one where-object FilterScript. For example I wanted to get list of processes on my server that are using more than 2MB of memory or have more than 400 file handles open. Following command shows how two filters were combined.

get-process | where {($_.WorkingSet -gt 1024*2048) -or ($_.HandleCount -gt 400)}

Following is list of logical operators that are available in PowerShell.

Logical OperatorMeaning
-andLogical and; true if both sides are true
-orLogical or; true if either side is true
-notLogical not; reverses true and false
!Logical not; reverses true and false
comments powered by Disqus

Blog Tags