Prompting for the Holidays

This should wait for a Friday Fun post but since it is December 1st I decided not to wait. It is that time of year again and my PowerShell prompt is colorful and sparkly.

My holiday themed PowerShell prompt (Image Credit: Jeff Hicks)

In my profile I have this code to use a new Prompt function.

I’ve posted the custom prompt before but now that I’m using GitHub a bit more, I’ve posted it as a Gist which you can find at

You can’t really pass parameters to a Prompt function so if you want to customize it you need to edit the file. One things I’ve thought of is changing the text so that instead of “Christmas in…” it might say “Santa Comes”

Santa Prompt
Santa Prompt (Image Credit: Jeff Hicks)

Or maybe this:

Another holiday promptAnother holiday prompt (Image Credit: Jeff Hicks)

And it doesn’t take much effort to support other holidays.

A Hanukkah versionA Hanukkah version (Image Credit: Jeff Hicks)

You can find this version of the prompt function at

Whatever your sentiment I hope you have a happy and healthy holiday season.

Update 2 December: It appears that some of the special characters I was using aren’t supported in Windows 10. [CHAR]14 is supposed to be a musical note and [CHAR]15 is like a snowflake. In Windows 10 they don’t display. You can select any other character you want, or none at all.

Friday Fun: Another Christmas Prompt

christmastree In last week’s Friday Fun post, I shared with you a PowerShell prompt that would display a festive Christmas countdown clock. This week I have another holiday related prompt function. This one is pretty straight forward and is not that much different from the default PowerShell prompt function.

I included some logic so that my customization only happens during the month of December and before Christmas. The prompt changes the background color of your console between DarkRed and DarkGreen. The first time you run it, the prompt will randomly select a color. You might want to run Clear-Host, or CLS after loading the prompt.

After that the background color will toggle leaving you with an effect like this:


It is interesting to see how different commands write to the console. You could even combine both of my prompts if you are in an especially festive mood.


There’s probably no practical value in this other than having some fun and maybe understanding some PowerShell scripting concepts. Hope your holiday shopping is going well. Have a great weekend.

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:


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.

A Timely PowerShell Prompt

021913_2047_WordTest1.pngDuring the course of writing a few scripts that refresh a specific part of the console, such as the recent Read-Host alternative, I realized that flashing colors wasn’t always necessary. The fact that I could update the same space on the screen meant I could write the same content with minor changes and it would look like the the screen as “flipping”. Essentially I was thinking of a clock.

So I thought it might be handy to have a clock as part of my PowerShell prompt. PowerShell has a built-in function called Prompt but you can replace it with your own version. The function will only last for as long as your PowerShell session so if you don’t like it, exit and restart PowerShell.

This is for the most part the basic function that shows PS and your current location. This prompt function will not work properly in the PowerShell ISE. The magic happens by always setting the cursor to the same coordinates in the PowerShell shell console. I use the same type of While loop I used in my other functions, only this time I’m waiting for the user to press any key, which would indicate the start of typing a command. Once that has been detected, the looping stops and the time ceases to be refreshed in the prompt.

You really need to see this live but here’s a screenshot example.

Then I thought it might be helpful to have the clock stand out so I added a little color.


The only issue I’ve found with these prompts, is that if you need to scroll in the console window, you’ll need to press the spacebar or type something so that the clock stops refreshing. Otherwise you are scrolling while PowerShell is trying to write to the console.

Instead of clock you could use a countdown timer. Or perhaps some sort of performance counter. For a prompt though, you need to make sure you can get and display the information in a few hundred milliseconds, otherwise the prompt will feel sluggish and unresponsive.

Enjoy and let me know where this leads you.

Pimp your Prompt

bling2If you are like me and live in PowerShell, then you spend a great deal of your day looking at your PowerShell prompt. That little indicator in the console and ISE that usually shows where you are. That little part of your PowerShell world is defined by a built-in function called Prompt. You can easily see the function like this:

This prompt is from PowerShell v4 but I’m pretty sure it is the same function that was used in v3. PowerShell v2 has a different function.

Did you notice that the newer function has a help link? Try it:

help prompt -online

You’ll get the online version of the about_prompts help topic. The great thing about the prompt function is that you can change it. I’ve posted a variety of prompts over the years. But here are 4 more for you to try out. These prompts should work in v3 and later. Most of the functions are simple additions to the standard prompt and should work for both the console and ISE. To try out the prompt you can paste the function into your PowerShell session. To make it “permanent”, insert it into your PowerShell profile script.

Include PowerShell Version

This prompt inserts the PowerShell major version into your prompt.

Include Admin

This prompt will test if you are running as Admin and if so, it inserts [ADMIN] in red text.

Include Computername

Do you like how a remoting session shows you the computer you are connected to? Why not have that all the time? All I’ve done is insert the local computername from the Computername environmental variable.


Auto Export Command History

This last version serves up a twist on transcription. When you run a transcript you get the command and results. But maybe all you want is a record of all the commands you ran. Sure, you could export command history at the end of your session, but you have to remember to do so and if you exceed your maximum history count, you’ll miss commands. In this prompt, everytime you hit enter, it gets the last command you ran and appends it to a log file. The log file is created in your PowerShell directory and uses the naming format of the PowerShell host, without spaces, a time stamp (YearMonthDay) and the process ID of the current PowerShell session. This allows you to keep multiple PowerShell sessions with separate logs. The log file will only record the command if it is different than the last one you ran. This also allows you to hit Enter without doing anything and not fill up your log.

If you temporarily paste in one of these Prompt functions, but don’t like it, you can simply restart PowerShell to get your original prompt. Or you can use this function to restore it.

This is handy to put into your PowerShell profile if you are experimenting with prompts. The Restore-Prompt simply defines a new Prompt function in the global scope. I’m using the default PowerShell prompt but you change it to whatever you wanted.

If you are doing something cool with your prompt, I hope you’ll share.