Powershell error returning hash table

Does anyone have any idea why the following code will result in an error, see additional comments after this function for more details

function callee    ([Hashtable]$arg0) {
    [Hashtable]$hashtable = @{}
    $hashtable = $arg0
    $hashtable.add('passed', $True)
    # $hashtable                            ######## toggle this line
    $type = $hashtable.GetType()
    Write-Host "$type"
    return $hashtable
}

function caller {
    [Hashtable]$hashtable = @{'00'='0'}
    $hashtable = callee $hashtable        ##### returns error here
    $hashtable.add('returned', $True)
    $hashtable
}
caller

error message: Cannot convert the value "System.Object []" to the type "System.Object []" to enter "System.Collections.Hashtable".

I get an error in many instances, I tried to narrow it down to an example that is easy to reproduce. It looks like it is changing the hash table to an array of objects, and therefore it will not return it? This allows me to modify the hash table and return it, but when I try to display it, does it change it? Is this the same effect that I get when I start adding code to the called party function?

+3
source
1

# $hashtable, . "" , PowerShell . return .

+8

All Articles