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

This entry was posted in Powershell Basics. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s