Friday Fun – Get Happy Holiday

Today’s Friday Fun is my version of a script originally posted a few years ago by The PowerShell Guy. I’ll list the code but you really need to run it to enjoy it.

#requires -version 2.0

#This must be run from the PowerShell console. NOT in the ISE.

#this is based on a script originally posted by The PowerShell Guy
#http://thepowershellguy.com/blogs/posh/default.aspx

$Greeting = "$([char]14) **Happy Holidays** $([char]14)"

Clear-Host
Write-host "`n"
$Peek = " ^ "
$tree = "/|\"
$i = 20
$pos = $host.ui.rawui.CursorPosition
#adjust to center the display
$offset = ($host.ui.rawui.WindowSize.Width - 72)/2

write-host -fore 'red' ($peek.PadLeft($i-1).PadRight(36) * 2)
write-host -fore 'green' ($tree.PadLeft($i-1).PadRight(36) * 2)

1..16 | Foreach {
    #build out the tree
    $tree = $tree -replace "/(.*)\\",'//$1\'
    write-host -fore 'green' ($tree.PadLeft($i).PadRight(36) * 2)
    $i++  
}

write-host -fore 'green' ("|||".PadLeft(19).PadRight(36) *2 )
write-host -fore 'green' ("|||".PadLeft(19).PadRight(36) *2)

$rect = New-Object System.Management.Automation.Host.Rectangle
$rect.top = $pos.y
$rect.Right = 70
$rect.Bottom = $pos.y + 19
$buffer = $host.ui.rawui.getbuffercontents($rect)
#random number object
$R = new-object system.random
$ball = new-object System.Management.Automation.Host.BufferCell
$ball.backgroundColor = $host.ui.rawui.BackgroundColor

1..150 | ForEach {
    sleep -Milliseconds 100
    #get a random position
    $rx = $r.Next(19)
    $ry = $r.Next(70)

    #define a collection of figures to be used as ornaments
    $ornaments = '@','*','#',":"
    #get a random ornament
    $ball.Character = Get-Random $ornaments
    $ball.ForegroundColor = $r.next(16)

    if ($buffer[$rx,$ry].Character -eq '/') {$buffer[$rx,$ry] = $ball}
    if ($buffer[$rx,$ry].Character -eq '\') {$buffer[$rx,$ry] = $ball}
    $host.ui.rawui.SetBufferContents($pos,$buffer)
}

#write the greeting centered
$pos.y = $pos.y + 22
$pos.x = 36 - (($Greeting.Length)/2)
$host.ui.rawui.CursorPosition=$pos

Write-Host $Greeting -Fore 'red'

This is probably the epitome of PowerShell fun: not practical in any way but still done with PowerShell. Enjoy.

Download Get-HappyHoliday

Post to Twitter Post to Plurk Post to Yahoo Buzz Post to Delicious Post to Digg Post to Facebook Post to FriendFeed Post to Google Buzz Post to Ping.fm Post to Reddit Post to Slashdot Post to StumbleUpon Post to Technorati

About the Author

PowerShell.org Announcer

This is the official account for PowerShell.org and sponsor announcements.