In the code below I'm trying to pass a hashtable into a function but it always changes its type to an Object[]
function Show-Hashtable{
param(
[Parameter(Mandatory = $true)][Hashtable] $input
)
return 0
}
function Show-HashtableV2{
param(
[Parameter(Mandatory = $true)][ref] $input
)
write-host $input.value.GetType().Name
return 0
}
[Hashtable]$ht=@{}
$ht.add( "key", "val" )
# for test
[int]$x = Show-HashtableV2 ([ref]$ht)
# main issue
[int]$x = Show-Hashtable $ht.clone()
Above I gave a try with $ht.Clone()
instead of $ht
but with no luck.
what I'm getting:
Object[]
Show-Hashtable : Cannot convert the "System.Object[]" value of type "System.Object[]" to type "System.Collections.Hashtable".
At C:\_PowerShellRepo\Untitled6.ps1:26 char:11
+ [int]$x = Show-Hashtable $ht #.clone()
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Show-Hashtable], PSInvalidCastException
+ FullyQualifiedErrorId : ConvertToFinalInvalidCastException,Show-Hashtable
I am asking for the direction in which to look. What is wrong with my code?