CmdID

CmdID / PowerShell / Cmdlets / Measure

Measure-Command

Measures the time it takes to run scriptblocks and cmdlets. PowerShell reference

From the PowerShell reference 2 parameters

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Measures the time it takes to run scriptblocks and cmdlets. The Measure-Command cmdlet runs a scriptblock or cmdlet internally, times the execution of the operation, and returns the execution time. NOTE: scriptblocks run by Measure-Command run in the current scope, not a child scope.

Measure-Command [-InputObject <PSObject>] [-Expression] <ScriptBlock> [<CommonParameters>]

Measure a command

Measure-Command { Get-EventLog "Windows PowerShell" }Identify

Trips 2 Sigma rules: mediumEventLog Query Requests By Builtin Utilities by Ali Alwashali, Nasreddine Bencherchali (Nextron Systems); mediumPotentially Suspicious EventLog Recon Activity Using Log Query Utilities by Nasreddine Bencherchali (Nextron Systems), X__Junior (Nextron Systems)

Compare two outputs from Measure-Command

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

Piping input to Measure-Command

# Perform a simple operation to demonstrate the InputObject parameter # Note that no output is displayed. 10, 20, 50 | Measure-Command -Expression { for ($i=0; $i -lt $_; $i++) {$i} }Identify

Displaying output of measured command

# Perform the same operation as above adding Out-Default to every execution. # This will show that the ScriptBlock is in fact executing for every item. 10, 20, 50 | Measure-Command -Expression {for ($i=0; $i -lt $_; $i++) {$i}; "$($_)" | Out-Default }Identify

Measuring execution in a child scope

$foo = 'Value 1' $null = Measure-Command { $foo = 'Value 2' } $foo $null = Measure-Command { & { $foo = 'Value 3' } } $fooIdentify

Its page in the reference: Measure-Command.

Parameters

2 in the PowerShell reference
-ExpressionSpecifies the expression that is being timed. Enclose the expression in braces ({}).
-InputObjectObjects 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.