给定多个 -Filters 的 powershell Get-ChildItem [英] powershell Get-ChildItem given multiple -Filters

查看:47
本文介绍了给定多个 -Filters 的 powershell Get-ChildItem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Get-ChildItem-Filter 属性是否有允许您同时应用多个过滤器的语法?即类似于下面的内容,我想在两者中使用通配符找到一些不同但特定命名的 .dll?

Is there a syntax for the -Filter property of Get-ChildItem to allow you to apply multiple filters at the same time? i.e. something like the below where I want to find a few different but specific named .dll's with the use of a wildcard in both?

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

还是我需要将其拆分为多个 Get-ChildItem 调用?因为我想通过管道传递这个结果.

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

推荐答案

Get-ChildItem 中的 -Filter 参数仅支持单个字符串/条件 AFAIK.这里有两种方法可以解决您的问题:

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

您可以使用接受多个字符串进行匹配的 -Include 参数.这比 -Filter 慢,因为它在 cmdlet 中进行搜索,而 -Filter 在提供级别上完成(在 cmdlet 获取结果之前,它可以处理他们).但是,它易于编写和运行.

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"

您也可以使用 -Filter 来获取所有 DLL,然后在 where 语句中过滤掉您想要的那些.

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.*' }

这篇关于给定多个 -Filters 的 powershell Get-ChildItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆