Skip to content

Latest commit

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..

PowerShell - working with Progress Bar

This PowerShell script generates a number between 0 and 1000000. It calculates an average value, which is surprisingly leading to the middle. SecondsRemaining parameter from Write-Progress cmdlet is reused to show total time used. Additionally CPU load bar is added.

random

$date=Get-Date; $cpudate=Get-Date$cpuload= (Get-Counter"\\$(hostname)\processor(_total)\% processor time").CounterSamples.CookedValue;
while (1-match1) {
$random=Get-Random-Minimum 0-Maximum 1000000$divider=$divider+1; [int64]$total+=$random; [int64]$average=$total/$dividerWrite-Progress-Id 1-Activity "Current:$random Total:$total Divider:$divider"-Status "Average:$average"-PercentComplete ([int64]$average/10000) -CurrentOperation "Divide sum ($total) by total generated count ($divider)"-SecondsRemaining ([int64]((Get-Date)-$date).TotalSeconds) -ErrorAction SilentlyContinue
$cputime=Get-Dateif ([int64]($cputime-$cpudate).TotalSeconds -gt10) {$cpuload= (Get-Counter"\\$(hostname)\processor(_total)\% processor time").CounterSamples.CookedValue; $cpudate=Get-Date}
Write-Progress-Id 2-Activity "Current CPU Load (10 seconds refresh interval)"-Status "Current CPU load - $($cpuload.ToString("##"))%"-PercentComplete ([int64]$cpuload) -ErrorAction SilentlyContinue
}