PowerShell Logo Small

Measure-Object



This is the built-in help made by Microsoft for the command 'Measure-Object', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Calculates the numeric properties of objects, and the characters, words, and lines in string objects, such as files of text.

SYNTAX


Measure-Object [[-Property] [<String[]>]] [-Average] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable
[<System.String>]] [-InputObject [<PSObject>]] [-Maximum] [-Minimum] [-Sum] [<CommonParameters>]
Measure-Object [[-Property] [<String[]>]] [-Character] [-IgnoreWhiteSpace] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}]
[-InformationVariable [<System.String>]] [-InputObject [<PSObject>]] [-Line] [-Word] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The Measure-Object cmdlet calculates the property values of certain types of object. Measure-Object performs three types of measurements, depending on the parameters in the
command.


The Measure-Object cmdlet performs calculations on the property values of objects. It can count objects and calculate the minimum, maximum, sum, and average of the numeric
values. For text objects, it can count and calculate the number of lines, words, and characters.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=293990
Compare-Object
ForEach-Object
Group-Object
New-Object
Select-Object
Sort-Object
Tee-Object
Where-Object

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>get-childitem | measure-object



This command counts the files and folders in the current directory.










-------------------------- EXAMPLE 2 --------------------------

PS C:\>get-childitem | measure-object -property length -minimum -maximum -average



This command displays the minimum, maximum, and sum of the sizes of all files in the current directory, and the average size of a file in the directory.










-------------------------- EXAMPLE 3 --------------------------

PS C:\>get-content C:\test.txt | measure-object -character -line -word



This command displays the number of characters, words, and lines in the Text.txt file.










-------------------------- EXAMPLE 4 --------------------------

PS C:\>get-process | measure-object -property workingset -minimum -maximum -average



This command displays the minimum, maximum, and average sizes of the working sets of the processes on the computer.










-------------------------- EXAMPLE 5 --------------------------

PS C:\>import-csv d:\test\serviceyrs.csv | measure-object -property years -minimum -maximum -average



This command calculates the average years of service of the employees of a company.

The ServiceYrs.csv file is a CSV file that contains the employee number and years of service of each employee. The first row in the table is a header row of "EmpNo, Years".

When you use Import-Csv to import the file, the result is a PSCustomObject with note properties of EmpNo and Years. You can use Measure-Object to calculate the values of
these properties, just like any other property of an object.










-------------------------- EXAMPLE 6 --------------------------

PS C:\>get-childitem | measure-object -property psiscontainer -max -sum -min -average

Count : 126
Average : 0.0634920634920635
Sum : 8
Maximum : 1
Minimum : 0
Property : PSIsContainer



This example demonstrates the Measure-Object can measure Boolean values. In this case, it uses the PSIsContainer Boolean property to measure the incidence of folders (vs.
files) in the current directory.