Powershell Get-ChildItem with Multiple Filters

Is there any syntax for the -Filter Get-ChildItem property so that you can apply multiple filters at the same time? that is, something like below, where I want to find several different but specific .dlls using a wildcard in both?

Get-ChildItem -Path $myPath -Filter "MyProject.Data*.dll", "EntityFramework*.dll"

or do I need to break this down into multiple Get-ChildItem calls? because I'm looking to convey the result of this.

+5
source share
2 answers

The -Filter parameter in Get-ChildItem supports only one AFAIK line / condition. Here are two ways to solve your problem:

You can use the -Include parameter, which takes multiple lines to match. This is slower than -Filter because it searches the cmdlet, and -Filter runs at the grant level (before the cmdlet receives the results so that it can process them). However, it is easy to write and work.

 #You have to use -Recurse to make -Include available even though it just a single level search Get-ChildItem -Include "MyProject.Data*.dll", "EntityFramework*.dll" -Recurse 

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

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

You can sift only one value with -Filter, while -Include can take several values, for example, ".dll, * .exe".

0
source

All Articles