Forum Discussion
JulianMilano
Jan 11, 2024Copper Contributor
IndexOf does not return the first value of an array!?
I'm tearing my hair out to find out why my code is not returning the first element of an array and thus created this sample code to test what I was seeing and found that the same thing happens. In t...
- Jan 11, 2024
I figured it out. The variables have different types so IndexOf will never find the value in the array:
$minValue | Get-Member TypeName: System.Double 100 | Get-Member TypeName: System.Int32
The solution is to convert the lookup value from a Double to Integer:
[int]$minValue = ($containers | Measure-Object -Minimum).Minimum # or $minValue = ($containers | Measure-Object -Minimum).Minimum -as [int]
Tested and works gr8!
JulianMilano
Jan 11, 2024Copper Contributor
I figured it out. The variables have different types so IndexOf will never find the value in the array:
$minValue | Get-Member TypeName: System.Double 100 | Get-Member TypeName: System.Int32
The solution is to convert the lookup value from a Double to Integer:
[int]$minValue = ($containers | Measure-Object -Minimum).Minimum
# or
$minValue = ($containers | Measure-Object -Minimum).Minimum -as [int]
Tested and works gr8!