PoshCode Archive  Artifact Content

Artifact 89bd6b1bc7aea2b620175856c58e3fe293682a440b8a03b536c7f6fb8046fec7:

  • File Start-Countdown.ps1 — part of check-in [adbdfcfcc9] at 2018-06-10 13:24:38 on branch trunk — Initiates a countdown on your session. Can be used instead of Start-Sleep (user: Josh_Atwell size: 2019)

# encoding: ascii
# api: powershell
# title: Start-Countdown
# description: Initiates a countdown on your session.  Can be used instead of Start-Sleep
# version: 1.0
# type: function
# author: Josh_Atwell
# license: CC0
# function: Start-Countdown
# x-poshcode-id: 3378
# x-archived: 2017-04-30T12:33:04
# x-published: 2012-04-20T13:24:00
#
# Use case is to provide visual countdown progress during “sleep” times
# http://www.vtesseract.com/post/21414227113/start-countdown-function-a-visual-for-start-sleep
#
function Start-Countdown{
<#
	.Synopsis
	 Initiates a countdown on your session.  Can be used instead of Start-Sleep.
	 Use case is to provide visual countdown progress during "sleep" times
	 
	.Example
	 Start-Countdown -Seconds 10
	 
	 This method will clear the screen and display descending seconds
	
	.Example
	 Start-Countdown -Seconds 10 -ProgressBar
	 
	 This method will display a progress bar on screen without clearing.
	 	 
	.Link
	 http://www.vtesseract.com/
	.Description
====================================================================
Author(s):		Josh Atwell <josh.c.atwell@gmail.com>
File: 			Start-Countdown.ps1
Date:			2012-04-19
Revision: 		1.0
References:		www.vtesseract.com

====================================================================
Disclaimer: This script is written as best effort and provides no 
warranty expressed or implied. Please contact the author(s) if you 
have questions about this script before running or modifying
====================================================================
#>
Param(
[INT]$Seconds = (Read-Host "Enter seconds to countdown from"),
[Switch]$ProgressBar,
[String]$Message = "Blast Off!"
)
Clear-Host
while ($seconds -ge 1){
If($ProgressBar){
	Write-Progress -Activity "Countdown" -SecondsRemaining $Seconds -Status "Time Remaining"
	Start-Sleep -Seconds 1
}ELSE{
	Write-Output $Seconds
	Start-Sleep -Seconds 1
	Clear-Host
}
$Seconds --
}
Write-Output $Message
}