Time a PowerShell Command (Measure-Command)
Measure exactly how long a command, pipeline or script block takes to execute.
01Command
$ Measure-Command { Get-ChildItem -Recurse -File } | Select-Object TotalSeconds02What 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
04Undo
✓No undo needed — this command does not change persistent state.
05Sources
- Measure-CommandEvidence: Documents Measure-Command running a scriptblock and returning a TimeSpan with detailed properties like TotalMilliseconds and TotalSeconds.
- Measure-CommandEvidence: 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
Use Windows Package Manager to install, search, and upgrade thousands of applications from the community repository in one command.
Understand PowerShell's execution policy scopes and set the one that lets you run your own local scripts without gutting the security model.
Search inside text files and logs with regex, returning file, line number and match.