Last active
December 6, 2018 15:04
-
-
Save jdhitsolutions/f85eb9474c04d40c79ec to your computer and use it in GitHub Desktop.
PowerShell Christmas Prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
display a colorful Christmas countdown prompt | |
[♫♪Christmas in 18.15:22:08֍♦] PS C:\> | |
This should work in the console with a True Type font and | |
the Powershell ISE | |
this prompt requires a TrueType font | |
you would put this in your profile script so that it | |
only runs in December 1-24 | |
#> | |
if ((Get-Date).Month -eq 12 -AND (Get-Date).Day -lt 25) { | |
#load the Christmas prompt | |
Function Prompt { | |
#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 | |
$myChars = "♫","♪","♦","*","֍" | |
$front = -join ($myChars | Get-Random -count 2) | |
#-join (14,15,42 | Get-Random -Count 2 | Foreach { $_ -as [char] }) | |
$back = -join ($myChars | Get-Random -count 2) | |
#-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-Object { | |
$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 | |
#the function needs to write something to the pipeline | |
" PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) " | |
} #end function | |
} #If December |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://jdhitsolutions.com/blog/powershell/6252/your-christmas-powershell-prompt/ for more details.