在脚本执行期间显示时钟 [英] Show a clock during execution of script

查看:32
本文介绍了在脚本执行期间显示时钟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在遍历项目列表并对每个项目进行写入进度.

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?

例如用

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

作为每秒的基础.但这是否可以在同一个 powershell 窗口中实现?

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

推荐答案

像这样:

$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()

这篇关于在脚本执行期间显示时钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆