Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
933 views
in Technique[技术] by (71.8m points)

web services - Write-Progress for 10 Minutes PowerShell

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...