Hi
I'm trying to create a hash table from two arrays, for which I'm going to plot some charts. But dependen on how I do it I get some different and weird behavior.
These are the two variables:
PowerCLI> $xlsx.group[0].time.Split(",")
200815124551
200815125051
200815125551
200815010051
200815010551
200815011051
200815011551
200815012051
200815012551
200815013051
PowerCLI> $xlsx.group[0].metricvalue.Split(",")
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
My script1:
function create_hash ([array] $keys, [array] $values) {
$h = @{}
$i = 0
do {$h[$keys[$i]] = $values[$i]; $i++;} until ($i -eq $keys.length)
$h
}
Output:
PowerCLI> create_hash $xlsx.group[0].time.Split(",") $xlsx.group[0].metricvalue.Split(",")
Name Value
---- -----
200815010051 0.0
200815125551 0.0
200815011551 0.0
200815011051 0.0
200815012551 0.0
200815010551 0.0
200815013051 0.0
200815012051 0.0
200815124551 0.0
200815125051 0.0
PowerCLI> create_hash $xlsx.group[0].metricvalue.Split(",") $xlsx.group[0].time.Split(",")
Name Value
---- -----
0.0 200815013051
So looking a the two outputs the first one the time, comes out 'out of order' and the second one only one value comes out :(
Changing things a bit still doesn't do it.
My Script2:
function create_hash ([array] $keys, [array] $values) {
$h = @{}
$i = 0
do {$h[$keys[$i]] = $values[$i]; $i++;$h} until ($i -eq $keys.length)
}
Output:
PowerCLI> create_hash $xlsx.group[0].time.Split(",") $xlsx.group[0].metricvalue.Split(",")
Name Value
---- -----
200815124551 0.0
200815125051 0.0
200815124551 0.0
200815124551 0.0
200815125051 0.0
200815125551 0.0
200815124551 0.0
200815010051 0.0
200815125051 0.0
200815125551 0.0
200815124551 0.0
200815010051 0.0
200815125051 0.0
200815125551 0.0
200815010551 0.0
200815010051 0.0
200815125551 0.0
200815011051 0.0
200815010551 0.0
200815124551 0.0
200815125051 0.0
200815010051 0.0
200815125551 0.0
200815011551 0.0
200815011051 0.0
200815010551 0.0
200815124551 0.0
200815125051 0.0
200815010051 0.0
200815125551 0.0
200815011551 0.0
200815011051 0.0
200815010551 0.0
200815012051 0.0
200815124551 0.0
200815125051 0.0
200815010051 0.0
200815125551 0.0
200815011551 0.0
200815011051 0.0
200815012551 0.0
200815010551 0.0
200815012051 0.0
200815124551 0.0
200815125051 0.0
200815010051 0.0
200815125551 0.0
200815011551 0.0
200815011051 0.0
200815012551 0.0
200815010551 0.0
200815013051 0.0
200815012051 0.0
200815124551 0.0
200815125051 0.0
PowerCLI> create_hash $xlsx.group[0].MetricValue.Split(",") $xlsx.group[0].time.Split(",")
Name Value
---- -----
0.0 200815124551
0.0 200815125051
0.0 200815125551
0.0 200815010051
0.0 200815010551
0.0 200815011051
0.0 200815011551
0.0 200815012051
0.0 200815012551
0.0 200815013051
Again the first one is way off and the last one is correct but name and value should be switch around...
Can't get my head around this, what's wrong ?