r/PowerShell • • 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

25 comments sorted by

View all comments

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

1

u/Lee_Dailey [grin] Dec 27 '19

howdy l33t_d0nut,

the triple-backtick/code-fence thing fails miserably on Old.Reddit ... so, if you want your code to be readable on both Old.Reddit & New.Reddit you likely otta stick with using the code block button.

it would be rather nice if the reddit devs would take the time to backport the code fence stuff to Old.Reddit ... [sigh ...]

take care,
lee