Friday 18 November 2022

Powershell Sleep with GUI feedback - Powershell Sleep Feedback timer

 We often need pauses or sleep in our powershell scripts. 

However it can be annoying not to know where the sleep or pause is at. 

The following function gives a visual GUI feedback of the sleep in the script


Example here  (30 seconds remaining)



To acheive this add this function to your script, and call it with the command

sleep-progress 30      



Function Sleep-Progress($seconds) {
$s = 0;
Do {
$p = [math]::Round(100 - (($seconds - $s) / $seconds * 100));
Write-Progress -Activity "Waiting..." -Status "$p% Complete:" -SecondsRemaining ($seconds - $s) -PercentComplete $p;
[System.Threading.Thread]::Sleep(1000)
$s++;
}
While($s -lt $seconds);

}

No comments:

Post a Comment