【发布时间】:2015-02-18 19:20:28
【问题描述】:
这是一个通过参数接受哈希表数组的函数:
function abc () {
Param([Hashtable[]]$tables)
$tables.count
}
使用示例:
PS C:\> abc -tables @{ a = 10 }, @{ b = 20 }, @{ c = 30 }
3
这是一个通过管道接受哈希表的函数:
function bcd () {
Param([parameter(ValueFromPipeline=$true)][Hashtable]$table)
$input.count
}
使用示例:
PS C:\> @{ a = 10 }, @{ b = 20 }, @{ c = 30 } | bcd
3
有没有办法定义可以通过参数或管道通过相同参数接受哈希表数组的函数? IE。可以通过上述两种方式调用的函数。请注意,我需要将整个哈希表数组放在一个变量中(因此在上面的 bcd 中使用了 $input)。
【问题讨论】:
标签: arrays function powershell hashtable pipeline