Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.