Export (0) Print
Expand All
Expand Minimize

Measure-Command

Measure-Command

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

Syntax

Parameter Set: Default
Measure-Command [-Expression] <ScriptBlock> [-InformationAction <System.Management.Automation.ActionPreference> {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend} ] [-InformationVariable <System.String> ] [-InputObject <PSObject> ] [ <CommonParameters>]




Detailed 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 braces ({}). The parameter name ("Expression") is optional.


Aliases

none

Required?

true

Position?

1

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-InformationAction<System.Management.Automation.ActionPreference>

Aliases

ia

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-InformationVariable<System.String>

Aliases

iv

Required?

false

Position?

named

Default Value

none

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.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

true (ByValue)

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see    about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • System.Management.Automation.PSObject

    You can pipe an object to Measure-Command.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • 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>".

Examples

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

This command measures the time it takes to run a Get-EventLog command that gets the events in the Windows PowerShell event log.


PS C:\> Measure-Command { Get-EventLog "windows powershell" }

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

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 Path parameter to get only .txt files in the C:\Windows directory and its subdirectories.


PS C:\> Measure-Command {Get-ChildItem –Path C:\Windows\*.txt -Recurse}

 

The second command measures the time it takes to process a recursive Get-ChildItem command that uses the provider-specific Filter parameter.


PS C:\> Measure-Command {Get-ChildItem C:\Windows -Filter "*.txt" -Recurse}

Related topics


Invoke-Command

Trace-Command

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft