Filtering Multiple File Types

by Jan 14, 2011

If you want to filter files based on multiple extensions, you should use this filter:

filter Where-Extension {
param(
[String[]]
$extension = ('.bmp', '.jpg', '.wmv')
)

$_ |
Where-Object {
$extension -contains $_.Extension
}

}

To find all *.log-files and all *.txt-files in your Windows folder, use it like this:

Dir $env:windir -recurse -ea 0 | Where-Extension .log,.txt

Twitter This Tip!
ReTweet this Tip!