-
-
Save evoelker/fcd8dc1563e15a6f8e5e11fdd93880cf to your computer and use it in GitHub Desktop.
Powershell sleep function, with progress bar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Sleep-Progress($seconds) | |
{ | |
<# | |
.SYNOPSIS | |
Function to Start-Sleep with a progress bar | |
.DESCRIPTION | |
Runs the 'Start-Sleep' command using the with a progress bar. Time is passed to the function in seconds as an argument. | |
.NOTES | |
# Updated from original to include the 'Wait time' in minutes and seconds | |
.EXAMPLE | |
Sleep-Progress 300 | |
.LINK | |
https://gist.github.com/evoelker/fcd8dc1563e15a6f8e5e11fdd93880cf | |
https://gist.github.com/ctigeek/bd637eeaeeb71c5b17f4 | |
#> | |
$doneDT = (Get-Date).AddSeconds($seconds) | |
while($doneDT -gt (Get-Date)) { | |
$secondsLeft = $doneDT.Subtract((Get-Date)).TotalSeconds | |
$percent = ($seconds - $secondsLeft) / $seconds * 100 | |
Write-Progress -Activity "Waiting $($([timespan]::fromseconds($seconds)).ToString("mm\:ss")) minutes ..." -Status "Waiting..." -SecondsRemaining $secondsLeft -PercentComplete $percent | |
[System.Threading.Thread]::Sleep(500) | |
} | |
Write-Progress -Activity "Waiting $($([timespan]::fromseconds($seconds)).ToString("mm\:ss")) minutes ..." -Status "Waiting..." -SecondsRemaining 0 -Completed | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment