Last night I spoke at DAYSPUG in Dayton Ohio, and since Christmas is only about 10 days away – I thought it would be fun to introduce two Christmas-related PowerShell Functions that I threw together.
The two functions are:
- New-ChristmasTree – This function generates an awesome, and mostly tacky animated, flashing Christmas tree in the PowerShell console.
- Get-DaysUntilChristmas – This function uses New-TimeSpan and Get-Date to calculate the number of days until Christmas. The output is something like “There are 10 days until Christmas!”
Here is the New-ChristmasTree function:
function New-ChristmasTree { [array]$Colors = "DarkRed","Green","Red","White" $oldBG = $Host.UI.RawUI.BackgroundColor $Host.UI.RawUI.BackgroundColor = "Black" function New-Tree { Clear-Host $Color = $Colors | Get-Random Write-Host " O " -ForegroundColor $Color $Color = $Colors | Get-Random Write-Host " OOO " -ForegroundColor $Color $Color = $Colors | Get-Random Write-Host " OOOOO " -ForegroundColor $Color $Color = $Colors | Get-Random Write-Host " OOOOOOO " -ForegroundColor $Color $Color = $Colors | Get-Random Write-Host " OOOOOOOOO " -ForegroundColor $Color $Color = $Colors | Get-Random Write-Host " OOOOOOOOOOO " -ForegroundColor $Color $Color = $Colors | Get-Random Write-Host " OOOOOOOOOOOOO " -ForegroundColor $Color $Color = $Colors | Get-Random Write-Host " OOOOOOOOOOOOOOO " -ForegroundColor $Color $Color = $Colors | Get-Random Write-Host " OOOOOOOOOOOOOOOOO " -ForegroundColor $Color $Color = $Colors | Get-Random Write-Host " OOOOOOOOOOOOOOOOOOO " -ForegroundColor $Color $Color = $Colors | Get-Random Write-Host " OOOOOOOOOOOOOOOOOOOOO " -ForegroundColor $Color $Color = $Colors | Get-Random Write-Host " OOOOOOOOOOOOOOOOOOOOOOOOO " -ForegroundColor $Color $Color = $Colors | Get-Random Write-Host " OOOOOOOOOOOOOOOOOOOOOOOOOOO " -ForegroundColor $Color Start-Sleep -Seconds 1 } New-Tree New-Tree New-Tree New-Tree New-Tree New-Tree New-Tree New-Tree New-Tree New-Tree $Host.UI.RawUI.BackgroundColor = $oldBG Clear-Host }
Here is the Get-DaysUntilChristmas function:
function Get-DaysUntilChristmas { $Christmas = Get-Date 12/25 $Today = Get-Date $TimeSpan = New-TimeSpan -Start $Today -End $Christmas $Days = $TimeSpan.Days Write-Host "There are $Days days until Christmas!" }
Here is a screenshot of the Get-DaysUntilChristmas function in action:
Reblogged this on Sharepoint… and commented:
A wonderful christmas tree in Powershell
Thanks Anatoly! Very much appreciated!
Cheers!
Ryan