Category Archives: Measure

Measure-Command

NAME
    Measure-Command

SYNOPSIS
    Measures the time it takes to run script blocks and cmdlets.

SYNTAX
    Measure-Command [-Expression] <scriptblock> [-InputObject <psobject>] [<CommonParameters>]

DESCRIPTION
    The Measure-Command cmdlet runs a script block or cmdlet internally, times the execution of the operation, and returns the execution time.

PARAMETERS
    -Expression <scriptblock>
        Specifies the expression that is being timed. Enclose the expression in curly braces ({}). The parameter name (“Expression”) is optional.

        Required?                    true
        Position?                    1
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -InputObject <psobject>
        Specifies objects representing the expressions to be measured. Enter a Variable that contains the objects or type a command or expression that gets the objects.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.PSObject
        You can pipe an object to Measure-Command.

OUTPUTS
    System.TimeSpan
        Measure-Command returns a time span object that represents the result.

NOTES

        For more information, type “Get-Help Measure-Command -detailed”. For technical information, type “Get-Help Measure-Command -full”.

         When specifying multiple values for a parameter, use commas to separate the values. For example, “<parameter-name> <value1>, <value2>”.

    ————————– EXAMPLE 1 ————————–

    C:\PS>Measure-Command { Get-Eventlog “windows powershell” }

    Description
    ———–
    This command measures the time it takes to run a “Get-Eventlog” command that gets the events in the Windows PowerShell event log.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Measure-Command {Get-ChildItem c:\windows -include *.txt -recurse}

    Days             : 0
    Hours             : 0
    Minutes         : 0
    Seconds         : 8
    Milliseconds     : 618
    Ticks             : 86182763
    TotalDays         : 9.9748568287037E-05
    TotalHours        : 0.00239396563888889
    TotalMinutes     : 0.143637938333333
    TotalSeconds     : 8.6182763
    TotalMilliseconds : 8618.2763

    C:\PS>Measure-Command {Get-ChildItem c:\windows -filter “*.txt” -recurse}

    Days             : 0
    Hours             : 0
    Minutes         : 0
    Seconds         : 1
    Milliseconds     : 140
    Ticks             : 11409189
    TotalDays         : 1.32050798611111E-05
    TotalHours        : 0.000316921916666667
    TotalMinutes     : 0.019015315
    TotalSeconds     : 1.1409189
    TotalMilliseconds : 1140.9189

    Description
    ———–
    These commands show the value of using a provider-specific filter in Windows PowerShell commands. The first command measures the time it takes to process a recursive Get-ChildItem command that uses the Include parameter. The second command measures the time it takes to process a recursive Get-ChildItem command that uses the provider-specific Filter parameter.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113348
    Trace-Command
    Invoke-Command

Measure-Object

NAME
    Measure-Object

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

SYNTAX
    Measure-Object [-Average] [-Maximum] [-Minimum] [-Sum] [[-Property] <string[]>] [-InputObject <psobject>] [<CommonParameters>]

    Measure-Object [-Character] [-IgnoreWhiteSpace] [-Line] [-Word] [[-Property] <string[]>] [-InputObject <psobject>] [<CommonParameters>]

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.

PARAMETERS
    -Average [<SwitchParameter>]
        Displays the average value of the specified properties.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Character [<SwitchParameter>]
        Counts the number of characters in the input object.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -IgnoreWhiteSpace [<SwitchParameter>]
        Ignores white space in word counts and character counts. By default, white space is not ignored.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -InputObject <psobject>
        Specifies the objects to be measured. Enter a Variable that contains the objects, or type a command or expression that gets the objects.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     true (ByValue)
        Accept wildcard characters? false

    -Line [<SwitchParameter>]
        Counts the number of lines in the input object.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Maximum [<SwitchParameter>]
        Displays the maximum value of the specified properties.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Minimum [<SwitchParameter>]
        Displays the minimum value of the specified properties.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Property <string[]>
        Specifies one or more numeric properties to measure. The default is the Count (Length) property of the object.

        Required?                    false
        Position?                    1
        Default value                Count
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Sum [<SwitchParameter>]
        Displays the sum of the values of the specified properties.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    -Word [<SwitchParameter>]
        Counts the number of words in the input object.

        Required?                    false
        Position?                    named
        Default value
        Accept pipeline input?     false
        Accept wildcard characters? false

    <CommonParameters>
        This cmdlet supports the common parameters: Verbose, Debug,
        ErrorAction, ErrorVariable, WarningAction, WarningVariable,
        OutBuffer and OutVariable. For more information, type,
        “Get-Help about_CommonParameters“.

INPUTS
    System.Management.Automation.PSObject
        You can pipe objects to Measure-Object.

OUTPUTS
    GenericMeasureInfo or TextMeasureInfoObject

NOTES

    ————————– EXAMPLE 1 ————————–

    C:\PS>Get-ChildItem | Measure-Object

    Description
    ———–
    This command counts the files and folders in the current directory.

    ————————– EXAMPLE 2 ————————–

    C:\PS>Get-ChildItem | Measure-Object -Property length -Minimum -Maximum -Average

    Description
    ———–
    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 ————————–

    C:\PS>Get-Content C:\test.txt | Measure-Object -character -line -word

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

    ————————– EXAMPLE 4 ————————–

    C:\PS>Get-Process | Measure-Object -Property workingset -Minimum -Maximum -Average

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

    ————————– EXAMPLE 5 ————————–

    C:\PS>Import-Csv d:\test\serviceyrs.csv | Measure-Object -Property years -Minimum -Maximum -Average

    Description
    ———–
    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 ————————–

    C:\PS>Get-ChildItem | Measure-Object -Property psiscontainer -max -Sum -min -Average

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

    Description
    ———–
    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.

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113349
    Compare-Object
    ForEach-Object
    Group-Object
    New-Object
    Select-Object
    Sort-Object
    Tee-Object
    Where-Object