Share via


Measure-Command

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

Syntax

Default (Default)

Measure-Command
    [-InputObject <PSObject>]
    [-Expression] <ScriptBlock>
    [<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

Specifies the expression that is being timed. Enclose the expression in braces ({}). The parameter name ("Expression") is optional.

Parameter properties

Type:ScriptBlock
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:0
Mandatory:True
Value from pipeline:False
Value from pipeline by property name:False
Value from remaining arguments:False

-InputObject

Objects bound to the InputObject parameter are optional input for the ScriptBlock passed to the Expression parameter. Inside the ScriptBlock, $_ can be used to reference the current object in the pipeline.

Parameter properties

Type:PSObject
Default value:None
Supports wildcards:False
DontShow:False

Parameter sets

(All)
Position:Named
Mandatory:False
Value from pipeline:True
Value from pipeline by property name:False
Value from remaining arguments:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

Inputs

PSObject

You can pipe an object to Measure-Command.

Outputs

TimeSpan

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