Write-Progress for 10 Minutes PowerShell

后端 未结 1 1385
后悔当初
后悔当初 2020-12-19 16:55

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条回答
  • 2020-12-19 17:32

    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
    
    0 讨论(0)
提交回复
热议问题