Measure the numeric or string properties of objects
Syntax
Measure-Object [ [-property] string[] ] [-inputObject psobject]
[-average] [-sum] [-minimum] [-maximum]
[CommonParameters]
Measure-Object [ [-property] string[] ] [-inputObject psobject]
[-line] [-word] [-character] [-ignoreWhiteSpace]
[CommonParameters]
Key
-inputObject
The objects to be measured.
A command, expression or variable that contains the objects.
-property string[]
The property to measure.
-average
Average the values in the designated property.
-sum
Sum the values of the properties.
-minimum
Determine the minimum value of the properties.
-maximum
Determine the maximum value of the properties.
-line
Count the number of lines in the input object.
-word
Count the number of words in the input object.
-character
Count the number of characters in the input object.
-ignoreWhiteSpace
Ignore white space in word counts and character counts.
CommonParameters:
-Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutVariable.
Examples
Count the number of files and folders in the current directory:
PS C:\>get-childitem | measure-object
Display the size of the largest and the size of the smallest file in the current directory:
PS C:\>get-childitem | measure-object -property length -minimum -maximum
Count the number of words in the file SS64.txt
PS C:\>get-content C:\SS64.txt | measure-object -word
"The advantage of living is not measured by length, but by use; some men have lived long, and lived little; attend to it while you are in it" - Michel Eyquem de Montaigne
Related:
compare-object Compare the properties of objects
ForEach-object - Loop for each object in the pipeline
group-object - Group the objects that contain the same value for a common property
new-object - Create a new .Net object
select-object - Select objects based on parameters set in the Cmdlet command string
sort-object - Sort the input objects by property value
tee-object - Send input objects to two places
where-object - Filter input from the pipeline allowing operation on only certain objects
Equivalent bash command: expr - Evaluate expressions