Home » PowerShell » PowerShell: Filtering Objects vs Where-Object

PowerShell: Filtering Objects vs Where-Object

In this article I am going to compare the filter parameter with where-object. The teaching says, that filtering is more efficient.  In the case of where-object, all objects must be retrieved first and then filtering is performed. This takes time. If filtered first, only the filtered objects are retrieved. In this article we’ll look at this using Measure-Command.

Get-Childitem and Where-Object

Measure-Command {Get-Childitem -Path C:\ -File -Recurse -ErrorAction SilentlyContinue | Where-Object {$_.Extension -eq ".txt"}}


37 seconds is not bad. I have a SSD.

Get-Childitem with Filter

Measure-Command {Get-Childitem -Path C:\ -File -Recurse -ErrorAction SilentlyContinue -Filter *.txt}


8 seconds is much faster.


Filtering is much faster. But not all commands offer the possibility to filter. In many posts I use where-object instead of the filter parameter. Why? I’m used to it. I think i have to change. 😉 See also my article Measure-Command: A speed comparison (Foreach vs. Foreach-Object).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s



My name is Patrick Grünauer (pewa2303). I am from Austria. On sid-500 I write about Windows, Cisco and IT-Security in English and German. Have fun while reading!

Patrick Gruenauer
Follow SID-500 on