Friday Fun Christmas Countdown Prompt

christmaslights 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 this in the past. But some of you are new to PowerShell and may have missed it. Plus I’ve revised it a bit.

In PowerShell you have a built-in function called Prompt. It controls what you see in the console which is usually something like PS C:\>. But you can create your own Prompt function. Here’s my Christmas countdown prompt.

I’ve inserted plenty of comments so you should be able to understand how it works. In a nutshell, the prompt inserts a message that indicates how much time remains before December 25th of the current year. The text also includes some special characters to help embellish it and put you in the holiday mood. Finally, each character is written to the host with a random color. You can see that I used a Switch construct to evaluate the random number with an expression.

This function will work best in the PowerShell console. If you want to try it out you can copy and paste this function into your console session. Your PowerShell session will now look like this:

christmasprompt2014

The prompt will only last for as long as your PowerShell session is running. The next time you start PowerShell you will be back to your original prompt. If you enjoy this, put my Christmas prompt function in your PowerShell profile, but be sure it is called Prompt. When the holidays are over simply comment out the function. Or you could add some logic to your profile.

Ho-Ho-Ho! Have a great weekend.

Friday Fun: A Christmas Present for You

Over the years a number of people in the PowerShell community have shared Christmas and holiday related items. I’ve collected them and in some cases tweaked a little bit. This year I decided to wrap them all up in a module for you. This will work in PowerShell 2.0 and later.

As you look through the functions you can probably figure out what some of these functions do, but I don’t want to spoil the surprise. But here’s an example.
xmas

Grab a copy of the module and look at the commands within it.

Don’t need to run Prompt because it automatically will run when you load the module. Note that if you remove the module you won’t get your old prompt back. Simply restart PowerShell.

Hoping you have a happy and healthy holiday and a fantastic New Year.