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
Give your advice to big bosses and make money

Views: 836

Tags:

Powershell | Automation

Comments

6/23/2009 11:54:03 AM #

Sulumits Retsambew

nice article thanks

Sulumits Retsambew United States

6/23/2009 12:02:57 PM #

Sulumits Retsambew

nice post thanks

Sulumits Retsambew United States

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli

By Categories