I have a function that creates a hashtable and returns it. My problem is that when returned, its converted to a system object with 2 entried, and my hashtable at entry 3.
sample code:
Function Get-MyHashtable($props) {
$NewProps = New-Object System.Collections.Hashtable
$NewProps.add('Item1', $props.Value1)
$NewProps.add('Item2', $props.Value2)
return $Newprops
}
And my code, that uses the function
$NextgenProps = Get-Myhashtable -props $Somedatatoprocess
My challenge is that before returning $Newprops, it's a hashtable ($Newprops.gettype()) but $NextgenProps is a system.object containing 2 values ( 0 & 1) and then my hashtable.
I was expecting a hashtable returned, not a system.object.
(Get-MyHashtable -props @{ value1 = 'foo'; value2 = 'bar' }).GetType()isHashtable. You need to give an example of what$Somedatatoprocessis. And double check if the function definition you have provided is exactly what you have.$Props? AnArrayList? ... How did you create this? (are the entries really from your function?)$null = .... If you don't discard such output, it becomes part of a script or function's "return value" (stream of output objects). See this answer for more information.