The [Hashtable []] parameter, which can come from a pipeline or an argument
Here's a function that takes an array of hashtables via an argument:
function abc () {
Param([Hashtable[]]$tables)
$tables.count
}
Usage example:
PS C:\> abc -tables @{ a = 10 }, @{ b = 20 }, @{ c = 30 }
3
Here's the function that accepts Hashtables through the pipeline:
function bcd () {
Param([parameter(ValueFromPipeline=$true)][Hashtable]$table)
$input.count
}
Usage example:
PS C:\> @{ a = 10 }, @{ b = 20 }, @{ c = 30 } | bcd
3
Is there a way to define a function that can take a hashtable array through an argument, or a pipeline through the same parameter? That is, a function that can be called in both of the ways shown above. Note that I will need the entire array of hash tables in one variable (hence the use $input
above in bcd
).
+3
source to share