powershell Get-ChildItem given multiple -Filters

You can only use one value with -Filter, whereas -Include can accept multiple values, for example ".dll, *.exe".


The -Filter parameter in Get-ChildItem only supports a single string/condition AFAIK. Here's two ways to solve your problem:

You can use the -Include parameter which accepts multiple strings to match. This is slower than -Filter because it does the searching in the cmdlet, while -Filter is done on a provide-level (before the cmdlet gets the results so it can process them). However, it is easy to write and works.

#You have to specify a path to make -Include available, use .\* 
Get-ChildItem .\* -Include "MyProject.Data*.dll", "EntityFramework*.dll"

You could also use -Filter to get all DLLs and then filter out the ones you want in a where-statement.

Get-ChildItem -Filter "*.dll" .\* | Where-Object { $_.Name -match '^MyProject.Data.*|^EntityFramework.*' }

You may join the filter results in a pipe like this:

@("MyProject.Data*.dll", "EntityFramework*.dll") | %{ Get-ChildItem -File $myPath -Filter $_ }

Tags:

Powershell