我使用 filter
遇到了一些 Powershell 代码。命令。我从未见过这个命令,但它的工作原理基本上是这样的:
它似乎表现为一个函数。如果我运行 Get-Command filter
我回来了The term 'filter' is not recognized as the name of a cmdlet, function, script file, or operable program.
和 Get-Alias filter
也返回类似的消息。 Get-Help filter
只是在某处返回带有单词过滤器的 Cmdlet 和函数。如果我用 Google 搜索“Powershell 过滤器命令”,我会得到一堆关于各种命令的信息 -Filter
论据和 Where-Object
句法。
这个命令是什么,它的用途是什么?某处有关于它的文档吗?谢谢!
最佳答案
简而言之,过滤器是一个只能使用进程 block 的功能。基于此,in 可用于操作(过滤、修改...)管道对象。它们还允许您 e。 G。通过模块提供预定义的过滤功能,为您节省编写复杂的工作Where-Objects
脚本 block 100 次。
about functions
Filters
A filter is a type of function that runs on each object in the pipeline. A filter resembles a function with all its statements in a Process block. The following filter takes log entries from the pipeline and then displays either the whole entry or only the message portion of the entry:
filter Get-ErrorLog ([switch]$message)
{
if ($message) { Out-Host -InputObject $_.Message }
else { $_ }
}
这个link提供了有关包含一些示例的很好的解释。希望有帮助。
关于powershell - PowerShell 中的 filter 关键字有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56446577/