Skip to content

Instantly share code, notes, and snippets.

@evoelker
Forked from ctigeek/Start-Sleep.ps1
Last active February 17, 2022 14:55
Show Gist options
  • Save evoelker/fcd8dc1563e15a6f8e5e11fdd93880cf to your computer and use it in GitHub Desktop.
Save evoelker/fcd8dc1563e15a6f8e5e11fdd93880cf to your computer and use it in GitHub Desktop.

Revisions

  1. evoelker revised this gist Oct 30, 2017. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions Start-Progress.ps1
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,7 @@ function Sleep-Progress($seconds)
    Sleep-Progress 300
    .LINK
    https://gist.github.com/evoelker/fcd8dc1563e15a6f8e5e11fdd93880cf
    https://gist.github.com/ctigeek/bd637eeaeeb71c5b17f4
    #>
  2. evoelker revised this gist Oct 3, 2017. 2 changed files with 29 additions and 10 deletions.
    29 changes: 29 additions & 0 deletions Start-Progress.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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/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
    }
    10 changes: 0 additions & 10 deletions Start-Sleep.ps1
    Original file line number Diff line number Diff line change
    @@ -1,10 +0,0 @@
    function Start-Sleep($seconds) {
    $doneDT = (Get-Date).AddSeconds($seconds)
    while($doneDT -gt (Get-Date)) {
    $secondsLeft = $doneDT.Subtract((Get-Date)).TotalSeconds
    $percent = ($seconds - $secondsLeft) / $seconds * 100
    Write-Progress -Activity "Sleeping" -Status "Sleeping..." -SecondsRemaining $secondsLeft -PercentComplete $percent
    [System.Threading.Thread]::Sleep(500)
    }
    Write-Progress -Activity "Sleeping" -Status "Sleeping..." -SecondsRemaining 0 -Completed
    }
  3. @ctigeek ctigeek created this gist Mar 23, 2016.
    10 changes: 10 additions & 0 deletions Start-Sleep.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    function Start-Sleep($seconds) {
    $doneDT = (Get-Date).AddSeconds($seconds)
    while($doneDT -gt (Get-Date)) {
    $secondsLeft = $doneDT.Subtract((Get-Date)).TotalSeconds
    $percent = ($seconds - $secondsLeft) / $seconds * 100
    Write-Progress -Activity "Sleeping" -Status "Sleeping..." -SecondsRemaining $secondsLeft -PercentComplete $percent
    [System.Threading.Thread]::Sleep(500)
    }
    Write-Progress -Activity "Sleeping" -Status "Sleeping..." -SecondsRemaining 0 -Completed
    }