PowerShell for Windows Admins

Jul 7 2013   2:52PM GMT

Measure-Object



Posted by: Richard Siddaway
Tags:
PowerShell

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

 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.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

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: