Skip to content

Instantly share code, notes, and snippets.

@jdhitsolutions
Last active December 5, 2017 16:47
Show Gist options
  • Save jdhitsolutions/c26c0a4fb2112ca6e74e to your computer and use it in GitHub Desktop.
Save jdhitsolutions/c26c0a4fb2112ca6e74e to your computer and use it in GitHub Desktop.
PowerShell Prompt to Countdown Hanukkah
#this prompt counts down to the first day of Hanukkah 2017
<#
It appears that some of the special characters I was using aren't supported in Windows 10 unless you are using Raster fonts.
[CHAR]14 is supposed to be a musical note and [CHAR]15 is like a snowflake.
You can select any other character you want, or none at all.
#>
Function Prompt {
#get current year
$year = (Get-Date).year
#get a timespan between Hanukkah for this year and now
$time=[datetime]"12 December $year" - (Get-Date)
#turn the timespan into a string and strip off the milliseconds
$timestring = $time.ToString().Substring(0,10)
#this won't really work unless using Raster fonts for your console
#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] })
$front = "*"
$back = "*"
$text="[{0}Hanukkah begins {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 = "Blue"}
{$i -le 16 -and $i -gt 10} { $color = "Yellow" }
{$i -le 10 -and $i -gt 5} { $color = "DarkBlue" }
default { $color = "White" }
}
#write each colorized character
Write-Host $_ -nonewline -foregroundcolor $color -BackgroundColor Gray
} #foreach
#the function needs to write something to the pipeline
#Write (" PS " + (Get-Location) + "> ")
Write "PS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "
} #end function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment