Time Commands With Measure-Command
Measure the wall-clock time a script block takes to run.
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
!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-CommandEvidence: Measures the execution time of a script block or command.
Last verified: 2026-09-20 · Category: Developer
06Related solutions
Grep on Windows: Select-String
Search inside text files and logs with regex, returning file, line number and match.
Zip Files with Compress-Archive
Create or update a .zip from any files or folder contents straight from PowerShell.
Test a TCP port connection on Windows with Test-NetConnection
A built-in PowerShell one-liner that answers 'is port 5432/3389/443 actually open through this network?' — no telnet client needed.