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.
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.