powershell - 在 Powershell 中,$input 是做什么用的?

标签 powershell

这个问题在这里已经有了答案:





Pass object[] into a function in PowerShell

(1 个回答)


4年前关闭。




我试图创建一个哈希表,

$input = @{'G'=100;'E'=50;'D'=35;'A'=100}

并且无法弄清楚为什么它不会像往常一样使用 write-host 之类的命令显示。 ,或简单地 $input . write-host返回 System.Collections.ArrayList+ArrayListEnumeratorSimple . $input什么也没回。没有抛出错误。

凭直觉,我重命名了哈希表,然后繁荣,它看起来很正常。在 ISE 中打开一个新的 powershell 选项卡,我观察到变量 $input即使我没有在这种环境中定义它,也充满了智能感知。

现在我很好奇:这个系统变量 $input 有什么用?我在第 4 版。

最佳答案

It's an automatic variable :

$INPUT

Contains an enumerator that enumerates all input that is passed to a function. The $input variable is available only to functions and script blocks (which are unnamed functions). In the Process block of a function, the $input variable enumerates the object that is currently in the pipeline. When the Process block completes, there are no objects left in the pipeline, so the $input variable enumerates an empty collection. If the function does not have a Process block, then in the End block, the $input variable enumerates the collection of all input to the function.



这在 PowerShell 中也可用:
Get-Help about_Automatic_Variables

I also have an open feature request for Set-StrictMode to handle detection of this .

关于powershell - 在 Powershell 中,$input 是做什么用的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43241124/

相关文章:

powershell - 将 map 对象存储在数组中

powershell : replace character in TXT file in certain position

powershell - powershell 中的延迟管道执行?

c# - Azure UpdateDomain 可配置性

sql-server - 为什么 Invoke-Sqlcmd -OutputAs DataTables 为一条记录和多条记录返回不同的类型

json - Powershell - 从嵌套对象中获取多个值

powershell - VS Code 总是提示 : "older version of PackageManagement known to cause issues"

powershell - 从多个文件中读取数字并求和

powershell - 为什么powershell远程设置COM+应用的 'QueuingEnabled'会导致保存失败?

powershell - 如何使用powershell下载文件?