powershellmeasure-object

How to prevent PowerShell's Measure-Object cmdlet from truncating your data?


I am tryng to compare the following data to obtain the largest number:

$UserDeets 

name                 lastLogon
----                 ---------
Frank Ti 132273694413991065
Frank Ti 132279742884182029
Frank Ti 132282196073500496
Frank Ti 132272912975826719
Frank Ti 132282144707771693
Frank Ti 132228790551703041

To do this I am trying to use the built in 'measure' function. This is the code I am executing

($UserDeets| measure -Property lastLogon -Maximum ).Maximum

The results of this are as follows

1.322821960735E+17

As you can see althogh it is returning the correct data it is truncating the last few digits off.

Is there a way to prevent this truncation?


Solution

  • OK I have a solution to this. The answer is to not use 'measure'. This is a work around, but it gets the desired answer.

    First i sorted the array:

    $UserDeets = ($UserDeets | Sort-Object -Property LastLogon)
    

    the highest object will be at the end of the array and can be obtained like this:

    $UserDeets[-1]