I would like to use the keys from an input hashtable ($htInput) in an output hashtable ($htOutput) without knowing the specific key names only their numeric position. Can I access the individual input hashtable keys using the $counter variable in the for loop:
$main = {
Begin {
Write-Host "SO Question Begin..." -ForegroundColor Black -BackgroundColor Green
}
Process {
try {
$htInput = @{Alpha = 1; Bravo = 2; Charlie = 3; Delta = 4; Echo = 5}
$htOutput = @()
for ($counter = 0; $counter -lt $htInput.Count; $counter++) {
$rzlt = $rzlt + $counter
$htOutput += $rzlt
}
# Expected Output: $htOutput = @{Alpha = 0; Bravo = 1; Charlie = 3; Delta = 6; Echo = 10}
# Actual Output : $htOutput = @(0; 1; 3; 6; 10)
return $htOutput
} catch {
Write-Host "Error: $($_.Exception)" -ForegroundColor White -BackgroundColor Red
break
}
}
End {
if ($?) {
Write-Host "SO Question End..." -ForegroundColor Black -BackgroundColor Green
}
}
}
& $main
The expected output is:
$htOutput = @{Alpha = 0; Bravo = 1; Charlie = 3; Delta = 6; Echo = 10}
but the actual output is:
$htOutput = @(0; 1; 3; 6; 10)
Please advise?