{"id":2261,"date":"2012-04-27T10:05:56","date_gmt":"2012-04-27T14:05:56","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=2261"},"modified":"2012-04-27T10:05:56","modified_gmt":"2012-04-27T14:05:56","slug":"friday-fun-powershell-countdown","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/","title":{"rendered":"Friday Fun: PowerShell Countdown"},"content":{"rendered":"<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/countdown.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/countdown-150x150.png\" alt=\"\" title=\"countdown\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-2262\" \/><\/a>Recently, <a href=\"http:\/\/www.vtesseract.com\" title=\"Visit Josh's blog\" target=\"_blank\">Josh Atwell<\/a> posted a PowerShell <a href=\"http:\/\/www.vtesseract.com\/post\/21414227113\/start-countdown-function-a-visual-for-start-sleep\" title=\"Check out the original post\" target=\"_blank\">script <\/a>that performed a countdown. Naturally, I was inspired and did the whole \"embrace and extend\" thing. Don't get me wrong: Josh's script is perfectly fine. I saw some opportunities to try some things and use it as a teaching device. If nothing else, let's have a little fun.<\/p>\n<p>First off, here's my version, then I'll go over a few highlights.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nFunction Start-Countdown {<br \/>\n<#\n comment based help is in the download version\n#><\/p>\n<p>Param(<br \/>\n[Parameter(Position=0,HelpMessage=\"Enter seconds to countdown from\")]<br \/>\n[Int]$Seconds = 10,<br \/>\n[Parameter(Position=1,Mandatory=$False,<br \/>\nHelpMessage=\"Enter a scriptblock to execute at the end of the countdown\")]<br \/>\n[scriptblock]$Scriptblock,<br \/>\n[Switch]$ProgressBar,<br \/>\n[Switch]$Clear,<br \/>\n[String]$Message = \"Blast Off!\"<br \/>\n)<\/p>\n<p>#save beginning value for total seconds<br \/>\n$TotalSeconds=$Seconds<\/p>\n<p>#get current cursor position<br \/>\n$Coordinate = New-Object System.Management.Automation.Host.Coordinates<br \/>\n$Coordinate.X=$host.ui.rawui.CursorPosition.X<br \/>\n$Coordinate.Y=$host.ui.rawui.CursorPosition.Y<\/p>\n<p>If ($clear) {<br \/>\n    Clear-Host<br \/>\n    #find the middle of the current window<br \/>\n    $Coordinate.X=[int]($host.ui.rawui.WindowSize.Width\/2)<br \/>\n    $Coordinate.Y=[int]($host.ui.rawui.WindowSize.Height\/2)<br \/>\n}<\/p>\n<p>#define the Escape key<br \/>\n$ESCKey = 27<\/p>\n<p>#define a variable indicating if the user aborted the countdown<br \/>\n$Abort=$False<\/p>\n<p>while ($seconds -ge 1) {<\/p>\n<p>    if ($host.ui.RawUi.KeyAvailable)<br \/>\n    \t\t{<br \/>\n    \t\t$key = $host.ui.RawUI.ReadKey(\"NoEcho,IncludeKeyUp,IncludeKeyDown\")<\/p>\n<p>    \t\tif ($key.VirtualKeyCode -eq $ESCkey)<br \/>\n    \t\t\t{<br \/>\n                #ESC was pressed so quit the countdown and set abort flag to True<br \/>\n    \t\t\t$Seconds = 0<br \/>\n                $Abort=$True<br \/>\n    \t\t\t}<br \/>\n    \t\t}<\/p>\n<p>    If($ProgressBar){<br \/>\n        #calculate percent time remaining, but in reverse so the progress bar<br \/>\n        #moves from left to right<br \/>\n        $percent=100 - ($seconds\/$TotalSeconds)*100<br \/>\n    \tWrite-Progress -Activity \"Countdown\" -SecondsRemaining $Seconds -Status \"Time Remaining\" -PercentComplete $percent<br \/>\n    \tStart-Sleep -Seconds 1<br \/>\n    } Else {<br \/>\n        if ($Clear) {<br \/>\n          Clear-Host<br \/>\n        }<br \/>\n        $host.ui.rawui.CursorPosition=$Coordinate<br \/>\n        #write the seconds with padded trailing spaces to overwrite any extra digits such<br \/>\n        #as moving from 10 to 9<br \/>\n        $pad=($TotalSeconds -as [string]).Length<br \/>\n        if ($seconds -le 10) {<br \/>\n            $color=\"Red\"<br \/>\n        }<br \/>\n        else {<br \/>\n            $color=\"Green\"<br \/>\n        }<br \/>\n        Write-Host \"$(([string]$Seconds).Padright($pad))\" -foregroundcolor $color<br \/>\n    \tStart-Sleep -Seconds 1<br \/>\n    }<br \/>\n    #decrement $Seconds<br \/>\n    $Seconds--<br \/>\n} #while<\/p>\n<p>if (-Not $Abort) {<br \/>\n    if ($clear) {<br \/>\n        #if $Clear was used, center the message in the console<br \/>\n        $Coordinate.X=$Coordinate.X - ([int]($message.Length)\/2)<br \/>\n    }<\/p>\n<p>    $host.ui.rawui.CursorPosition=$Coordinate<\/p>\n<p>    Write-Host $Message -ForegroundColor Green<br \/>\n    #run the scriptblock if specified<br \/>\n    if ($scriptblock) {<br \/>\n        Invoke-Command -ScriptBlock $Scriptblock<br \/>\n    }<br \/>\n}<br \/>\nelse {<br \/>\n    Write-Warning \"Countdown aborted\"<br \/>\n}<br \/>\n} #end function<br \/>\n<\/code><\/p>\n<p>The basic premise hasn't really changed. Run the function specifying the number of seconds to count down and at the end of the countdown display a message. I thought why not really do something? So I added an optional Scriptblock parameter. At the end of the countdown, it will be executed using Invoke-Command.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nif ($scriptblock) {<br \/>\n  Invoke-Command -ScriptBlock $Scriptblock<br \/>\n}<br \/>\n<\/code><\/p>\n<p>Next, I decided to add a way to abort the countdown. If you run the function in the ISE and use the Progress bar parameter, you can click the Stop button. In the console, you could press Ctrl+C but that seemed a little heavy handed to me so I inserted code to watch for a key press, specifically the ESC key. If the key press is detected, I set a flag variable to False and the seconds to 0 to break out of the While loop.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n#define the Escape key<br \/>\n$ESCKey = 27<\/p>\n<p>#define a variable indicating if the user aborted the countdown<br \/>\n$Abort=$False<\/p>\n<p>while ($seconds -ge 1) {<\/p>\n<p>    if ($host.ui.RawUi.KeyAvailable)<br \/>\n    \t\t{<br \/>\n    \t\t$key = $host.ui.RawUI.ReadKey(\"NoEcho,IncludeKeyUp,IncludeKeyDown\")<\/p>\n<p>    \t\tif ($key.VirtualKeyCode -eq $ESCkey)<br \/>\n    \t\t\t{<br \/>\n                #ESC was pressed so quit the countdown and set abort flag to True<br \/>\n    \t\t\t$Seconds = 0<br \/>\n                $Abort=$True<br \/>\n    \t\t\t}<br \/>\n    \t\t}<br \/>\n...<br \/>\n<\/code><\/p>\n<p>After the loop I inserted commands to check if the countdown was aborted or not. If not, then I display the message and run the scriptblock, if supplied.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nif (-Not $Abort) {<br \/>\n    if ($clear) {<br \/>\n        #if $Clear was used, center the message in the console<br \/>\n        $Coordinate.X=$Coordinate.X - ([int]($message.Length)\/2)<br \/>\n    }<\/p>\n<p>    $host.ui.rawui.CursorPosition=$Coordinate<\/p>\n<p>    Write-Host $Message -ForegroundColor Green<br \/>\n    #run the scriptblock if specified<br \/>\n    if ($scriptblock) {<br \/>\n        Invoke-Command -ScriptBlock $Scriptblock<br \/>\n    }<br \/>\n}<br \/>\nelse {<br \/>\n    Write-Warning \"Countdown aborted\"<br \/>\n}<br \/>\n<\/code><\/p>\n<p>I like the use of Write-Progress. I don't think it gets enough attention. I decided to add in the progress bar which is incremented based on a percentage of how much time is to go.  <\/p>\n<p><code lang=\"PowerShell\"><br \/>\n$percent=100 - ($seconds\/$TotalSeconds)*100<br \/>\nWrite-Progress -Activity \"Countdown\" -SecondsRemaining $Seconds -Status \"Time Remaining\" -PercentComplete $percent<br \/>\n<\/code><\/p>\n<p>I'm subtracting the percent value from 100 so that the progress bar moves from left to right. It looked odd to me to move from \"Full\" to \"Empty\", although I suppose for a countdown that is more accurate. You can switch this back.<\/p>\n<p>My last change is how the countdown is handled in the console, if you don't use the progress bar. In Josh's version he cleared the screen and then wrote the current time, clearing the screen each time. The effect is you see the number change in the upper left corner of the console. But what if you don't want to clear the screen? Writing the number will use a new line for each value. Using Write-Host with -NoNewLine will simply append to the current line and look ugly. So I decided to have some fun with raw host data.<\/p>\n<p>First, I grab the coordinates of the cursor's current position using the RawUI property from $host.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n#get current cursor position<br \/>\n$Coordinate = New-Object System.Management.Automation.Host.Coordinates<br \/>\n$Coordinate.X=$host.ui.rawui.CursorPosition.X<br \/>\n$Coordinate.Y=$host.ui.rawui.CursorPosition.Y<br \/>\n<\/code><\/p>\n<p>I want this because I can use the coordinates to put the cursor to a specific location in the console.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n        #write the seconds with padded trailing spaces to overwrite any extra digits such<br \/>\n        #as moving from 10 to 9<br \/>\n        $pad=($TotalSeconds -as [string]).Length<br \/>\n        if ($seconds -le 10) {<br \/>\n            $color=\"Red\"<br \/>\n        }<br \/>\n        else {<br \/>\n            $color=\"Green\"<br \/>\n        }<br \/>\n        Write-Host \"$(([string]$Seconds).Padright($pad))\" -foregroundcolor $color<br \/>\n    \tStart-Sleep -Seconds 1<br \/>\n    }<br \/>\n<\/code><\/p>\n<p>I also added code and logic so that the number is displayed in Green using Write-Host until it reaches 10, at which point it is written to the console in red.<\/p>\n<p>I also use the coordinates for some fun if you use -Clear. I put the countdown timer in the center of the console window. In order to do that I had to find the dimensions of the window and divide by 2, treating each value as an [INT].<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n#find the middle of the current window<br \/>\n$Coordinate.X=[int]($host.ui.rawui.WindowSize.Width\/2)<br \/>\n$Coordinate.Y=[int]($host.ui.rawui.WindowSize.Height\/2)<br \/>\n<\/code><\/p>\n<p>Finally, I decided to also center the message. This meant figuring out the message length and then adjusting the X coordinate.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nif ($clear) {<br \/>\n   #if $Clear was used, center the message in the console<br \/>\n   $Coordinate.X=$Coordinate.X - ([int]($message.Length)\/2)<br \/>\n}<br \/>\n$host.ui.rawui.CursorPosition=$Coordinate<br \/>\n<\/code><\/p>\n<p>Curious to see what this looks like? (the clip has no audio)<\/p>\n<p><iframe loading=\"lazy\" width=\"420\" height=\"315\" src=\"http:\/\/www.youtube.com\/embed\/WxwsbpNWAow\" frameborder=\"0\" allowfullscreen><\/iframe><\/p>\n<p>You can download <a href='http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/Countdown2.txt' target='_blank'>Countdown2<\/a> and load the Start-Countdown function into your PowerShell session. Be sure to read the help.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, Josh Atwell posted a PowerShell script that performed a countdown. Naturally, I was inspired and did the whole &#8220;embrace and extend&#8221; thing. Don&#8217;t get me wrong: Josh&#8217;s script is perfectly fine. I saw some opportunities to try some things and use it as a teaching device. If nothing else, let&#8217;s have a little fun&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[271,4,8],"tags":[],"class_list":["post-2261","post","type-post","status-publish","format-standard","hentry","category-friday-fun","category-powershell","category-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Friday Fun: PowerShell Countdown &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Friday Fun: PowerShell Countdown &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Recently, Josh Atwell posted a PowerShell script that performed a countdown. Naturally, I was inspired and did the whole &quot;embrace and extend&quot; thing. Don&#039;t get me wrong: Josh&#039;s script is perfectly fine. I saw some opportunities to try some things and use it as a teaching device. If nothing else, let&#039;s have a little fun....\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2012-04-27T14:05:56+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/countdown-150x150.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Friday Fun: PowerShell Countdown\",\"datePublished\":\"2012-04-27T14:05:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/\"},\"wordCount\":591,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/countdown-150x150.png\",\"articleSection\":[\"Friday Fun\",\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/\",\"name\":\"Friday Fun: PowerShell Countdown &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/countdown-150x150.png\",\"datePublished\":\"2012-04-27T14:05:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/countdown.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2012\\\/04\\\/countdown.png\",\"width\":\"383\",\"height\":\"276\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2261\\\/friday-fun-powershell-countdown\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Friday Fun\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/friday-fun\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Friday Fun: PowerShell Countdown\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Friday Fun: PowerShell Countdown &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/","og_locale":"en_US","og_type":"article","og_title":"Friday Fun: PowerShell Countdown &#8226; The Lonely Administrator","og_description":"Recently, Josh Atwell posted a PowerShell script that performed a countdown. Naturally, I was inspired and did the whole \"embrace and extend\" thing. Don't get me wrong: Josh's script is perfectly fine. I saw some opportunities to try some things and use it as a teaching device. If nothing else, let's have a little fun....","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/","og_site_name":"The Lonely Administrator","article_published_time":"2012-04-27T14:05:56+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/countdown-150x150.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Friday Fun: PowerShell Countdown","datePublished":"2012-04-27T14:05:56+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/"},"wordCount":591,"commentCount":3,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/countdown-150x150.png","articleSection":["Friday Fun","PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/","name":"Friday Fun: PowerShell Countdown &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/countdown-150x150.png","datePublished":"2012-04-27T14:05:56+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/countdown.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/04\/countdown.png","width":"383","height":"276"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2261\/friday-fun-powershell-countdown\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Friday Fun","item":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},{"@type":"ListItem","position":2,"name":"Friday Fun: PowerShell Countdown"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":4830,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4830\/friday-fun-a-powershell-nap\/","url_meta":{"origin":2261,"position":0},"title":"Friday Fun: A PowerShell Nap","author":"Jeffery Hicks","date":"January 22, 2016","format":false,"excerpt":"I'm hoping that I'm not the only one who feels their butt dragging by mid to late afternoon. Let's say that's because we've been thundering through the day and by 3:00 we're a bit out of gas. Yeah, I'll go with that. I find myself wanting to close my eyes\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"antique-watch-150x225","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/01\/antique-watch-150x225_thumb.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4145,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4145\/friday-fun-christmas-countdown-prompt\/","url_meta":{"origin":2261,"position":1},"title":"Friday Fun Christmas Countdown Prompt","author":"Jeffery Hicks","date":"December 5, 2014","format":false,"excerpt":"It's that time of year again where PowerShell can make all your wishes come true. Ok, maybe that's a bit much, but PowerShell is the gift that keeps giving all year long. Again, maybe too much. How about this? Here's a revised version of my Christmas countdown prompt. I've posted\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"christmaslights","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/12\/christmaslights-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":6252,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/6252\/your-christmas-powershell-prompt\/","url_meta":{"origin":2261,"position":2},"title":"Your Christmas PowerShell Prompt","author":"Jeffery Hicks","date":"December 6, 2018","format":false,"excerpt":"Continuing my fun with PowerShell prompts and because we are in the Christmas season. I\u2019m bringing back my Christmas countdown prompt. I have updated so it should work in both the traditional console and PowerShell ISE. The prompt displays a randomly colorized countdown message with some random decorations. You can\u2026","rel":"","context":"In &quot;Miscellaneous&quot;","block_context":{"text":"Miscellaneous","link":"https:\/\/jdhitsolutions.com\/blog\/category\/miscellaneous\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/12\/image_thumb-2.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/12\/image_thumb-2.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2018\/12\/image_thumb-2.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":478,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/478\/is-it-friday-yet\/","url_meta":{"origin":2261,"position":3},"title":"Is It Friday Yet?","author":"Jeffery Hicks","date":"November 5, 2009","format":false,"excerpt":"Some days the week just seems to drag on and on and on\u2026.Like many of you, I can\u2019t wait for the end of the work day on Friday afternoon. But how much longer is it until I can say, in a cliche ridden fashion, \u201cTGIF!\u201d Fortunately I have PowerShell to\u2026","rel":"","context":"In &quot;Miscellaneous&quot;","block_context":{"text":"Miscellaneous","link":"https:\/\/jdhitsolutions.com\/blog\/category\/miscellaneous\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9154,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9154\/a-wpf-countdown-timer\/","url_meta":{"origin":2261,"position":4},"title":"A WPF Countdown Timer","author":"Jeffery Hicks","date":"October 19, 2022","format":false,"excerpt":"Last year I released a PowerShell module called PSClock. The module contains a command to create a transparent WPF form displaying a clock. Shortly after, someone posted a request for a countdown timer. Not an unreasonable request and one I finally got around to implementing. However, I already had a\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"pscountdown timer","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/10\/countdowntimer.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/10\/countdowntimer.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/10\/countdowntimer.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/10\/countdowntimer.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":7956,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7956\/friday-fun-a-powershell-christmas-prompt\/","url_meta":{"origin":2261,"position":5},"title":"Friday Fun &#8211; A PowerShell Christmas Prompt","author":"Jeffery Hicks","date":"December 11, 2020","format":false,"excerpt":"Time for a new Friday Fun article. These articles use \"fun\" ways to teach you how to use PowerShell. The end goal may be silly, but hopefully the techniques and concepts are useful. Today I have an updated prompt function. You can customize your PowerShell prompt by creating a function\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/christmas-countdown.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/christmas-countdown.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/christmas-countdown.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/christmas-countdown.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/christmas-countdown.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/12\/christmas-countdown.png?resize=1400%2C800&ssl=1 4x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2261","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=2261"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2261\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2261"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2261"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2261"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}