powershell - PowerShell 中的 filter 关键字有什么作用?

标签 powershell

我使用 filter 遇到了一些 Powershell 代码。命令。我从未见过这个命令,但它的工作原理基本上是这样的:

enter image description here

它似乎表现为一个函数。如果我运行 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/

相关文章:

multithreading - 如何使用多线程脚本

PowerShell 函数 $ 输入参数

file - CMDExec如果存在则停止

powershell - 如何在Powershell中加载WPFToolkit程序集

Powershell 没有一些内置帮助主题

powershell - 在新线程powershell中调用函数

powershell - 为什么 PowerShell 重定向 >> 更改文本内容的格式?

powershell - 新 PSDrive --Persist 不起作用

azure - Windows 2019 IIS On Premise Application Insight 监视器状态

windows - 二进制将所有文件与指定目录(和子目录)中的所有文件进行比较