To improve Windows Server I suggest you ...

Powershell Bug: hash tables of length 1 are corrupted when returned from a function.

function SomeFunction
{
Write-Host "SomeFunction calling SomeOtherFunction"
$ht = SomeOtherFunction
Write-Host "Hash Table Returned"
for ($i=0; $i -lt $ht.length; $i++) {
$arrayEntry1 = $ht[$i][0]
$arrayEntry2 = $ht[$i][1]
Write-Host "($arrayEntry1, $arrayEntry2)"
}

Write-Host "SomeFunction calling SomeOtherOtherFunction"
$ht = SomeOtherOtherFunction
Write-Host "Hash Table Returned"
for ($i=0; $i -lt $ht.length; $i++) {
$arrayEntry1 = $ht[$i][0]
$arrayEntry2 = $ht[$i][1]
Write-Host "($arrayEntry1, $arrayEntry2)"
}
}

function SomeOtherFunction
{
Write-Host "SomeOtherFunction added one entry into the hash table"
$myHashTable = @()
$myHashTable += ,@(1,0.99)

Write-Host "This is what the hash table looks like before being returned."
for ($i=0; $i -lt $myHashTable.length; $i++) {
$arrayEntry1 = $myHashTable[$i][0]
$arrayEntry2 = $myHashTable[$i][1]
Write-Host "($arrayEntry1, $arrayEntry2)"
}
return $myHashTable
}

function SomeOtherOtherFunction
{
Write-Host "SomeOtherOtherFunction added one entry into the hash table"
$myHashTable = @()
$myHashTable += ,@(1,0.99)
$myHashTable += ,@([int32]::MinValue,[int32]::MinValue)

Write-Host "This is what the hash table looks like before being returned this time."
for ($i=0; $i -lt $myHashTable.length; $i++) {
$arrayEntry1 = $myHashTable[$i][0]
$arrayEntry2 = $myHashTable[$i][1]
Write-Host "($arrayEntry1, $arrayEntry2)"
}
return $myHashTable
}

1 vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Craig HourieCraig Hourie shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    0 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base