powershell - Passing hashtable as argument to a function in PS -
i have problem in powershell script :
when want pass hashtable function, hashtable not recognized hashtable.
function getlength(){ param( [hashtable]$input ) $input.length| write-output } $table = @{}; $obj = new-object psobject;$obj | add-member noteproperty size 2895 | add-member noteproperty count 5124587 $table["test"] = $obj $table.gettype() | write-output ` hashtable $tx_table = getlength $table `unable convert system.collections.arraylist+arraylistenumeratorsimple in system.collections.hashtable
why ?
$input
automatic variable enumerates input given.
chose other variable name , it'll work - although not might expect - number of entries in hashtable need inspect count
property:
function get-length { param( [hashtable]$table ) $table.count }
write-output
implied when leave $table.count
is.
also, ()
suffix in function name unnecessary syntactic sugar 0 meaning when declare parameters inline param()
- drop it
Comments
Post a Comment