Show a clock during execution of script

2019-09-02 04:44发布

I am looping through a list of items and doing a write-progress on each item.

Is it possible to show a timer during the script execution?

For example show $elapsedTime with

$elapsedTime = [system.diagnostics.stopwatch]::StartNew()

as basis each second. But would this be possible in the same powershell window?

2条回答
Bombasti
2楼-- · 2019-09-02 05:13

like this:

$elapsedTime = [system.diagnostics.stopwatch]::StartNew()

1..1000 | %{write-progress -activity "Working..." -status "$([string]::Format("Time Elapsed: {0:d2}:{1:d2}:{2:d2}", $elapsedTime.Elapsed.hours, $elapsedTime.Elapsed.minutes, $elapsedTime.Elapsed.seconds))" -percentcomplete ($_/10);}

$elapsedTime.stop()
查看更多
放我归山
3楼-- · 2019-09-02 05:31

Wouldn't something like this work:

1..100 | %{write-progress -activity "Search in Progress" -status "$_ Time: $($elapsedTime.Elapsed)" -percentcomplete $_;} 
查看更多
登录 后发表回答