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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -