Time a PowerShell Command (Measure-Command)

Measure exactly how long a command, pipeline or script block takes to execute.

WindowsdeveloperpowershellLow risk
Wrap the command in braces: Measure-Command { your-command } and read the returned TimeSpan (TotalSeconds/TotalMilliseconds).

01Command

Command
$ Measure-Command { Get-ChildItem -Recurse -File } | Select-Object TotalSeconds

02What it does

Measure-Command runs the scriptblock once and returns a TimeSpan object whose TotalSeconds and TotalMilliseconds properties give the elapsed time. Note the command's own output is swallowed — you see the timing, not the results, which keeps the measurement clean. For comparing two approaches, run each inside Measure-Command several times and average, since first-run JIT and caching distort single runs.

03Risk

RiskLow risk
!Warning: The wrapped command still runs for real — do not wrap destructive commands like Remove-Item just to time them.

04Undo

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

05Sources

  • Measure-Command
    Microsoft Learn · vendor-doc · 2026-09-17
    Evidence: Documents Measure-Command running a scriptblock and returning a TimeSpan with detailed properties like TotalMilliseconds and TotalSeconds.
  • Measure-Command
    SS64 · technical · 2026-09-17
    Evidence: Shows syntax examples of timing script blocks and notes that the command output is suppressed while timing.

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

06Related solutions