r/PowerShell • u/[deleted] • Dec 26 '19
Get-HappyNewYear - Yes, bored at work...
Just made a little function for fun, what do you think ?
<# Give you timeleft before NewYear
Wish you an happy NewYear if 1st january #>
Function Get-HappyNewYear {
# Variables
$ActualYear = (Get-Date).Year
$NextYear = $ActualYear + 1
$TimeLeft = New-TimeSpan -Start (Get-Date) -End ("01-01-$NextYear" -as [datetime])
$d = $TimeLeft.Days
$h = $TimeLeft.Hours
$m = $TimeLeft.Minutes
$s = $TimeLeft.Seconds
$Totalh = [math]::Round($TimeLeft.TotalHours)
# Job
Write-Host "There are $d day(s), $h hour(s), $m minute(s) and $s second(s) left before the New Year !"
if ((Get-Date).Day -eq 1 -and (Get-Date).Month -eq 1 ) {
Write-Host "But, actually it's 1st January so... HAPPY NEW YEAR $ActualYear !!!" -ForegroundColor Red -BackgroundColor Yellow
}
else {
Write-Host "So... Be patient, the new year is in $Totalh hour(s) and $m minute(s) !"
}
}
118
Upvotes
2
u/[deleted] Dec 27 '19
This is how you turn your function into a website with UniversalDashboard:
```
$dashboard = New-UDDashboard -Title 'Happy New Year' -Content {
New-UDElement -Tag 'div' -Endpoint {
Get-HappyNewYear
} -AutoRefresh -RefreshInterval 1
}
$Server = Start-UDDashboard -Port 10001 -Dashboard $dashboard
```
http://g.recordit.co/Dd2YNxxeb5.gif