PowerShell中的Boolean和所有传入管道对象

时间:2014-04-11 00:48:37

标签: powershell

将管道连接在一起最方便的方法是什么?如果每个传入的对象都被评估为真,则返回的值为true?如:

$fileList | % { Test-Path $_ } | Boolean-And

上面的代码片段应该测试fileList中的每个文件是否存在。但是没有'布尔 - 和'功能。是否有不同的名称/方式来做到这一点?

1 个答案:

答案 0 :(得分:3)

另一种可能性:

@($fileList | % { Test-Path $_ }) -notcontains $false 

作为管道功能:<​​/ p>

function And-Boolean
 { $input -notcontains $false }