Powershell – Measure-Object is not exact because of rounding/flooring

In case you want to get maximal value without rounding/flooring – to be exact you should not use Measure-Object. You need to enumerate array (which is also faster).


$a, $b | Measure-Object -Maximum
Result: Maximum : 1,6

Which is not what we wanted. For this we need to build own array and enumerate it:

$arr = @(

$max = ""
foreach ($item in $arr) {
    if ($item -gt $max) {
        $max = $item

Which results into:


Another method could be:

$arr | Sort-Object -Descending | Select-Object -First 1

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.