Categories

Measure-Object

One cmdlet that I don’t think gets used enough is Measure-Object. This enables you to find the minimum, maximum, sum and average of a set of numbers coming down the pipeline

PS> 1..12 | Measure-Object -Sum -Maximum -Minimum -Average

Count    : 12
Average  : 6.5
Sum      : 78
Maximum  : 12
Minimum  : 1
Property :

You can also work with properties:

PS> Get-Process | Measure-Object -Property Handles -Sum -Maximum -Minimum -Average

Count    : 59
Average  : 481.101694915254
Sum      : 28385
Maximum  : 2734
Minimum  : 0
Property : Handles

You don’t need to select all of the options.

PS> (Get-Process | Measure-Object -Property Handles -Average).Average
480.593220338983

Next time you need to find the maximum, minimum, average or sum remember measure-object instead of spending time writing your own routines

Leave a Reply