Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

A PowerShell Countdown Timer

Posted on December 6, 2017

The other day, during one of the monthly #PSTweetChat sessions, I exchanged some tweets with Joshua King. We got on the topic of countdown timers and he shared some code he uses for his YouTube channel. The command creates a progress bar and counts down, displaying some humorous messages along the way. There's absolutely nothing wrong with his solution but I can't help myself and am always looking to see what else it can do.  So after a bit of time with it, I came up with a version I call Start-PSCountdown. This is something I expect to be able to use in my PowerShell training classes and conferences.

Manage and Report Active Directory, Exchange and Microsoft 365 with
ManageEngine ADManager Plus - Download Free Trial

Exclusive offer on ADManager Plus for US and UK regions. Claim now!

My version, which should work on Windows PowerShell and PowerShell Core, accepts a few parameters. You can set the timer for anywhere between 1 and 60 minutes. The default is 5. You can also set a title for the progress bar and a countdown message. The rest of the display is randomly drawn from a list fun messages. I've added a few more in my version. I also added a dynamic parameter for something I call ProgressStyle. If PowerShell detects that you are using a Windows console, you will see the parameter. The downside with dynamic parameters is that you don't get tab completion or discovery with PSReadLine. The default behavior is to use the current setting for $host.PrivateData.ProgressbarBackgroundColor. But you can use a parameter value of Transparent which will set the progress bar background to the same color as the console, sort of making it transparent. Or you can use –Random and you'll get a random background color from a subset of console colors.

Note that as of today, the integrated PowerShell host in VS Code does not support Write-Host so you'll get a warning message.

The code for my function is on GitHub.

If you have suggestions or problems, please post a followup comment on the page.

I hope you'll let me know what you think and a big thanks to @WindosNZ.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

5 thoughts on “A PowerShell Countdown Timer”

  1. Josh King says:
    December 6, 2017 at 5:30 pm

    Interestingly, it’ll work in VS Code as long as it’s running in “powershell” and not the Integrated Console that’s part of the PowerShell extension. (Example: http://iforce.co.nz/i/x5kzuekb.x5g.png)

    Handy to know if you’re determined to only use Code during demos/presentations (I really need to break the ISE habit).

    Thanks for the awesome write up, script, and shoutout!

    1. Jeffery Hicks says:
      December 6, 2017 at 5:57 pm

      I only use the integrated console in VSCode. But that’s fine as I never use VSCode as a demo tool unless I’m demoing VSCode! The ISE is still a better presentation tool.

  2. Rob Duncan says:
    December 7, 2017 at 5:38 am

    Love it!

  3. Rob Duncan says:
    December 7, 2017 at 5:41 am

    I’ve added ‘Calculating the average air speed velocity of unladen Swallow ‘

    1. Jeffery Hicks says:
      December 7, 2017 at 10:13 am

      There’s really no end to this foolishness. I’m considering a version where the function would import from an external file. That would be the smart way to go and keep the function code a bit more manageable.

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d