powershell max/first/aggregate functions

Use the Measure-Object command:

C:\PS> 2,1,3 | Measure-Object -Maximum


Count    : 3
Average  :
Sum      :
Maximum  : 3
Minimum  :
Property :

Or to get just the max:

C:\PS> (2,1,3 | Measure -Max).Maximum

There’s also a Minimum, Average and Sum available as you can see from above. But you have to tell PowerShell to compute those with parameters to Measure-Object e.g. -Sum -Average etc.

Leave a Comment