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

by Viper 29. January 2009 15:37

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

Views: 488

Tags:

Powershell | Automation

Comments

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.6.1
Theme by Naveen Kohli

Recent

By Categories