Write-Progress for 10 Minutes PowerShell

梦想的初衷 提交于 2019-11-28 04:49:08

问题


Hi all is there a way we can show progress bar for 10 minutes with statistics of percentage completed how much time remaining for 10 Minutes? using Write-Progress.


回答1:


If I understand the question correctly the goal is to show some additional information in the progress messages. This can be done for example by using the Activity parameter. The script below only shows the idea (for 1 minute, for a shorter test). It should be modified in order to reflect actually needed format of the message and information to be shown.

$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
}

The progress looks like this:

57 % complete, remaining time 00:00:26
   Processing
   [oooooooooooooooooooooooooooooooooooooooooooooooooooooo


来源:https://stackoverflow.com/questions/13333223/write-progress-for-10-minutes-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!