PowerShell Measure-Object Cmdlet
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In the last blog post, we have discussed ForEach-Object cmdlet in PowerShell.
https://cloudaffaire.com/powershell-foreach-object-cmdlet/
In this blog post, we will discuss Measure-Object cmdlet in PowerShell. You can use Measure-Object cmdlet to perform calculation on a collection of objects. Measure-Object performs three types of measurements, depending on the parameters in the command. You can use Measure-Object cmdlet to calculate the count of the objects or count of object based on certain property. If the object is of type numeric, you can use Measure-Object cmdlet to calculate the Minimum, Maximum, Sum, Standard Deviation and Average of numeric values. If the object is of type string, you can use Measure-Object to count the number of lines, words, and characters.
Measure-Object Cmdlet Syntax:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
## Measure-Object ## [[-Property] ## [-InputObject ## [-StandardDeviation] ## [-Sum] ## [-AllStats] ## [-Average] ## [-Maximum] ## [-Minimum] ## [-Line] ## [-Word] ## [-Character] ## [-IgnoreWhiteSpace] ## [ |
Measure-Object Cmdlet Argument List:
- –AllStats: Indicates that the cmdlet displays all the statistics of the specified properties.
- –Average: Indicates that the cmdlet displays the average value of the specified properties.
- –Character: Indicates that the cmdlet counts the number of characters in the input objects.
- –IgnoreWhiteSpace: Indicates that the cmdlet ignores white space in character counts. By default, white space is not ignored.
- –InputObject: Specifies the objects to be measured. Enter a variable that contains the objects, or type a command or expression that gets the objects.
- –Line: Indicates that the cmdlet counts the number of lines in the input objects.
- –Maximum: Indicates that the cmdlet displays the maximum value of the specified properties.
- –Minimum: Indicates that the cmdlet displays the minimum value of the specified properties.
- –Property: Specifies one or more properties to measure. If you do not specify any other measures, Measure-Object counts the objects that have the properties you specify.
- –StandardDeviation: Indicates that the cmdlet displays the standard deviation of the values of the specified properties.
- –Sum: Indicates that the cmdlet displays the sum of the values of the specified properties.
- –Word: Indicates that the cmdlet counts the number of words in the input objects.
PowerShell Measure-Object Cmdlet:
Calculate Count, Sum, Average, Maximum And Minimum Values From A Collection Of Numeric Objects In PowerShell:
1 2 3 4 5 6 7 8 |
########################################## ## PowerShell | Cmdlet | Measure-Object ## ########################################## ## PowerShell Latest Version (5) ## get the count, sum, average, maximum and minimum values from a collection of numeric objects 1, 2, 3, 4, 5 | Measure-Object -Minimum -Maximum -Average -Sum |
Calculate Word Count, Line Count And Character Count From A Collection Of String Objects In PowerShell:
1 2 3 4 5 |
## get the word count, line count and charecter count from a collection of string objects "hello world", "welcome to cloudaffaire" | Measure-Object -Word -Line -Character "hello world", "welcome to cloudaffaire" | Measure-Object -Word -Line -Character -IgnoreWhiteSpace |
Perform Calculation On The Output Of A Cmdlet In PowerShell:
1 2 3 |
## perform calculation on the output of a cmdlet Get-Process | Measure-Object -Property WorkingSet64 -Minimum -Maximum -Average -Sum |
Hope you have enjoyed this article. In the next blog post, we will discuss Tee-Object cmdlet in PowerShell.
To get more details on PowerShell, kindly follow below official documentation