Time Commands With Measure-Command

Measure the wall-clock time a script block takes to run.

WindowsperformancescriptingpowershellLow risk
Run Measure-Command { ... } to print the elapsed time of the block.

01Command

Command
$ Measure-Command { 1..100000 | ForEach-Object { $_ * 2 } }

02What it does

Measure-Command runs a script block and returns a TimeSpan with total milliseconds and other fields. It is the simplest way to benchmark one implementation against another, and it suppresses the block's normal output so only timing is shown.

03Risk

RiskLow risk
RequirementsWindows 10/11 with PowerShell 5.1 or PowerShell 7+
!Warning: It measures elapsed time including I/O waits, and a single run can be noisy; average several runs for reliable results.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

  • Measure-Command
    Microsoft Learn · vendor-doc · 2026-09-20
    Evidence: Measures the execution time of a script block or command.

Last verified: 2026-09-20 · Category: Developer

06Related solutions