Filter by More Than One Criteria

by Apr 6, 2011

You should probably use Get-Childitem with its -filter parameter to list specific files because it is much faster than -include. This line will locate all log files recursively in your Windows folder structure:

Dir $env:windir -Filter *.log -Recurse -ErrorAction SilentlyContinue

With -filter, you cannot search for more than one search criterion at the same time. So what if you wanted to find all WAV-files, plus all BMP-files?
Use -include instead of -filter. Although it is slower, it is  also more versatile:

Dir $env:windir -Recurse -ErrorAction SilentlyContinue -include *.wav, *.bmp

 

Twitter This Tip!
ReTweet this Tip!