CmdID

CmdID / PowerShell / Cmdlets / Measure

Measure-Object

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

From the PowerShell reference 10 parameters Alias measure

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Calculates the numeric properties of objects, and the characters, words, and lines in string objects, such as files of text. 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. You can use Measure-Object to count objects or count objects with a specified Property. You can also use Measure-Object to calculate the Minimum, Maximum, Sum, StandardDeviation and Average of numeric values. For String objects, you can also use Measure-Object to count the number of lines, words, and characters.

Measure-Object [-InputObject <PSObject>] [[-Property] <String[]>] [-Sum] [-Average] [-Maximum] [-Minimum] [<CommonParameters>]
Measure-Object [-InputObject <PSObject>] [[-Property] <String[]>] [-Line] [-Word] [-Character] [-IgnoreWhiteSpace] [<CommonParameters>]

Count the files and folders in a directory

Get-ChildItem | Measure-ObjectIdentify

Measure the files in a directory

Get-ChildItem | Measure-Object -Property Length -Minimum -Maximum -Sum -AverageIdentify

Measure text in a text file

"One", "Two", "Three", "Four" | Set-Content -Path C:\Temp\tmp.txt Get-Content C:\Temp\tmp.txt | Measure-Object -Character -Line -WordIdentify

Measure objects containing a specified Property

$services = Get-Service $processes = Get-Process $services + $processes | Measure-Object $services + $processes | Measure-Object -Property DisplayNameIdentify

Measure the contents of a CSV file

Import-Csv D:\test\serviceyrs.csv | Measure-Object -Property Years -Minimum -Maximum -AverageIdentify

Measure Boolean values

Get-ChildItem | Measure-Object -Property PSIsContainer -Maximum -Sum -Minimum -AverageIdentify

Measure strings

# The newline character n separates the string into separate lines, as shown in the output. "OnenTwonThree" "OnenTwonThree" | Measure-Object -LineIdentify

Its page in the reference: Measure-Object.

Parameters

10 in the PowerShell reference
-AverageIndicates that the cmdlet displays the average value of the specified properties.
-CharacterIndicates that the cmdlet counts the number of characters in the input objects. NOTE: The Word, Char and Line switches count _inside_ each input object, as well as _across_ input objects. See Example 7.
-IgnoreWhiteSpaceIndicates that the cmdlet ignores white space in character counts. By default, white space is not ignored.
-InputObjectSpecifies the objects to be measured. Enter a variable that contains the objects, or type a command or expression that gets the objects. When you use the InputObject parameter with Measure-Object, instead of piping command results to Measure-Object, the InputObject value is treated as a single object. It is recommended that you use Measure-Object in the pipeline if you want to measure a collection of objects based on whether the objects have specific values in defined properties.
-LineIndicates that the cmdlet counts the number of lines in the input objects. NOTE: The Word, Char and Line switches count _inside_ each input object, as well as _across_ input objects. See Example 7.
-MaximumIndicates that the cmdlet displays the maximum value of the specified properties.
-MinimumIndicates that the cmdlet displays the minimum value of the specified properties.
-PropertySpecifies 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.
-SumIndicates that the cmdlet displays the sum of the values of the specified properties.
-WordIndicates that the cmdlet counts the number of words in the input objects. NOTE: The Word, Char and Line switches count _inside_ each input object, as well as _across_ input objects. See Example 7.