PowerShell Logo Small

Measure-Command



This is the built-in help made by Microsoft for the command 'Measure-Command', in PowerShell version 5 - as retrieved from Windows version 'Microsoft Windows Server 2012 R2 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

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

SYNTAX


Measure-Command [-Expression] <ScriptBlock> [-InformationAction {SilentlyContinue | Stop | Continue | Inquire | Ignore | Suspend}] [-InformationVariable [<System.String>]]
[-InputObject [<PSObject>]] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


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



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/p/?linkid=293989
Invoke-Command
Trace-Command

REMARKS

<

Examples


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

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



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 --------------------------

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}

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

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}

PS C:\>
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



These commands show the value of using a provider-specific filter in Windows PowerShell commands.