名前 Measure-Object 概要 Calculates the numeric properties of objects, and the characters, words, and lines in string objects, such as fi les of text. 構文 Measure-Object [[-Property] []] [-Average] [-InformationAction {SilentlyContinue | Stop | Continue | I nquire | Ignore | Suspend}] [-InformationVariable []] [-InputObject []] [-Maximum] [-Mi nimum] [-Sum] [] Measure-Object [[-Property] []] [-Character] [-IgnoreWhiteSpace] [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable []] [-InputObject []] [-Line] [-Word] [] 説明 The Measure-Object cmdlet calculates the property values of certain types of object. Measure-Object performs thr ee 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 calc ulate 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. パラメーター -Average [] Displays the average value of the specified properties. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Character [] Counts the number of characters in the input object. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -IgnoreWhiteSpace [] Ignores white space in word counts and character counts. By default, white space is not ignored. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -InformationAction [] 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -InformationVariable [] 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -InputObject [] Specifies the objects to be measured. Enter a variable that contains the objects, or type a command or expre ssion that gets the objects. When you use the InputObject parameter with Measure-Object, instead of piping command results to Measure-Obj ect, the InputObject value?even if the value is a collection that is the result of a command, such as ?Input Object (Get-Process)?is treated as a single object. Because InputObject cannot return individual properties from an array or collection of objects, it is recommended that if you use Measure-Object to measure a collec tion of objects for those objects that have specific values in defined properties, you use Measure-Object in the pipeline, as shown in the examples in this topic. 必須 false 位置 named 既定値 none パイプライン入力を許可する true (ByValue) ワイルドカード文字を許可する false -Line [] Counts the number of lines in the input object. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Maximum [] Displays the maximum value of the specified properties. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Minimum [] Displays the minimum value of the specified properties. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Property [] Specifies one or more numeric properties to measure. The default is the Count (Length) property of the objec t. 必須 false 位置 1 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Sum [] Displays the sum of the values of the specified properties. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false -Word [] Counts the number of words in the input object. 必須 false 位置 named 既定値 none パイプライン入力を許可する false ワイルドカード文字を許可する false このコマンドレットは、次の共通パラメーターをサポートします: Verbose、 Debug、ErrorAction、ErrorVariable、WarningAction、WarningVariable、 OutBuffer, PipelineVariable、および OutVariable。詳細については、 about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216) を参照してください。 入力 System.Management.Automation.PSObject You can pipe objects to Measure-Object. 出力 Microsoft.PowerShell.Commands.GenericMeasureInfo, Microsoft.PowerShell.Commands.TextMeasureInfo, Microsoft.Power Shell.Commands.GenericObjectMeasureInfo If you use the Word parameter, Measure-Object returns a TextMeasureInfo object. Otherwise, it returns a Gene ricMeasureInfo object. -------------------------- 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 comput er. -------------------------- 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. T he 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 Yea rs. You can use Measure-Object to calculate the values of these properties, just like any other property of an o bject. -------------------------- 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. 関連するリンク 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