写入进度10分钟PowerShell

Pow*_*ell 4 powershell sharepoint web-services powershell-2.0

大家好,有一种方法,我们可以显示进度条10分钟,统计百分比完成了10分钟的剩余时间?使用Write-Progress.

Rom*_*min 5

如果我正确理解了问题,目标是在进度消息中显示一些其他信息.这可以通过使用Activity参数来完成 .下面的脚本只显示了这个想法(1分钟,更短的测试).应对其进行修改,以反映实际需要的消息格式和要显示的信息.

$time = 60 # seconds, use you actual time in here
foreach($i in (1..$time)) {
    $percentage = $i / $time
    $remaining = New-TimeSpan -Seconds ($time - $i)
    $message = "{0:p0} complete, remaining time {1}" -f $percentage, $remaining
    Write-Progress -Activity $message -PercentComplete ($percentage * 100)
    Start-Sleep 1
}
Run Code Online (Sandbox Code Playgroud)

进度如下:

57 % complete, remaining time 00:00:26
   Processing
   [oooooooooooooooooooooooooooooooooooooooooooooooooooooo
Run Code Online (Sandbox Code Playgroud)