Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to filter a list of objects by its type in powershell. I can, of course, use the type name and string comparison to do that:

PS C:\> gci -r | where { $_.GetType().Name -eq "DirectoryInfo" }

but having roots in C#, I was looking for something like the is operator.

So, is my way the best or is there another way?

share|improve this question
up vote 3 down vote accepted

Powershell has an -is operator:

gci -r | where { $_ -is [System.IO.DirectoryInfo] }
share|improve this answer
For some reason I didn't found it. LOL. Thanks a lot! – Bruno Brant Jul 5 '12 at 19:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .