【发布时间】:2013-03-20 23:18:22
【问题描述】:
在过去的几个小时里,我试图弄清楚如何将脚本块传递给一个函数,以用作 where 对象的过滤器。我还没有找到任何文档,我一定是遗漏了一些东西。我在What is the recommended coding style for PowerShell? 中看到了“过滤器脚本:”和“功能:脚本”定义,但我不知道它们是如何使用的,我在任何地方都找不到。
function Test
{
Param(
$f,
$What
)
$x = $What | where $f
$x
}
$mywhat = @('aaa', 'b', 'abb', 'bac')
filter script:myfilter {$_ -like 'a*'}
Test -What $mywhat -xx $myfilter
有人可以指点我正确的方向吗?
【问题讨论】: