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

Friday Fun: Another Christmas Prompt

Posted on December 12, 2014December 11, 2014

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.

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!
Function Prompt {

#only change background color if in December
if ((Get-Date).Month -eq 12 -And (Get-Date).Day -lt 25) {
Switch ($host.ui.RawUI.BackgroundColor) {

"DarkGreen" { $c = "DarkRed" }
"DarkRed"   { $c = "DarkGreen" }
 Default    { 
            #get a random color
            $c = Get-Random -InputObject "DarkRed","DarkGreen"
            }

} #switch

$host.ui.RawUI.BackgroundColor = $c
}

"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "

}

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:

christmasprompt2014-redgreen

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.

Function Prompt {

#only change background color if in December
if ((Get-Date).Month -eq 12 -And (Get-Date).Day -lt 25) {
Switch ($host.ui.RawUI.BackgroundColor) {

"DarkGreen" { $c = "DarkRed" }
"DarkRed"   { $c = "DarkGreen" }
 Default    { 
            #get a random color
            $c = Get-Random -InputObject "DarkRed","DarkGreen"
            }

} #switch

$host.ui.RawUI.BackgroundColor = $c


#get current year
    $year = (Get-Date).year
    #get a timespan between Christmas for this year and now

    $time=[datetime]"25 December $year" - (Get-Date)
    #turn the timespan into a string and strip off the milliseconds
    $timestring = $time.ToString().Substring(0,11)

    #get random string of decorative characters
    $front = -join (14,15,42 | Get-Random -Count 2 | Foreach { $_ -as [char] })
    $back = -join (14,15,42 | Get-Random -Count 2 | Foreach { $_ -as [char] })
    $text="[{0}Christmas in {1}{2}]" -f $front,$timestring,$back

    #get each character in the text and randomly assign each a color
    $text.tocharArray() | foreach {

    $i = get-random -Minimum 1 -Maximum 20
    switch ($i) {
      {$i -le 20 -and $i -gt 15} { $color = "Red"}
      {$i -le 16 -and $i -gt 10} { $color = "Green" }
      {$i -le 10 -and $i -gt 5}{ $color = "DarkGreen"}
      default {$color = "White"}
    }

    #write each colorized character
    write-host $_ -nonewline -foregroundcolor $color
    } #foreach

} #if Christmas time

"PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "

} #end prompt function

christmasprompt2014-everything

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.


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

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