Created
December 30, 2015 14:46
-
-
Save jdhitsolutions/791c175e56fc9f56fab3 to your computer and use it in GitHub Desktop.
A New Year's Countdown script
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
#this must be run in the PowerShell console NOT the ISE | |
if ($host.name -ne 'ConsoleHost') { | |
Write-Warning "Sorry. This must be run in the PowerShell console." | |
#bail out | |
Return | |
} | |
#get window dimensions | |
$X = $host.ui.RawUI.WindowSize.width | |
#subtract 5 to accomodate the end of the script | |
$Y = $host.ui.RawUI.WindowSize.Height - 5 | |
#save current window title | |
$title = $host.ui.RawUI.WindowTitle | |
#get an array of console colors | |
$colors = [enum]::GetNames([consolecolor]) | |
#clear the screen | |
cls | |
#for every line of window height counting down | |
$Y..1 | Foreach { | |
#write a randomized colored row | |
1..$X | foreach { | |
Write-Host " " -BackgroundColor (Get-Random $colors) -NoNewline | |
} | |
#count down the last 10 | |
if ($_ -le 10) { | |
$host.ui.RawUI.WindowTitle = $_ | |
[console]::Beep() | |
Start-Sleep -Milliseconds 500 | |
} | |
} | |
$msg = "Happy New Year!" | |
$msg.ToCharArray() | foreach -Begin {Write-Host "`n"} -process { | |
Write-Host $_ -NoNewline -ForegroundColor (Get-Random $colors) -BackgroundColor (Get-Random $colors) | |
} -end { Write-Host "`n" } | |
#reset the window Title | |
$host.ui.RawUI.WindowTitle = $Title | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment