PowerShell for Windows Admins

Jul 7 2013   2:52PM GMT


Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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

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

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: