Yesterday I wrote that there’s a way to use Internet Explorer for logging, I mentioned I didn’t like it too much, that’s why I wrote the logging function that uses a .NET form and DataGridView, well today I will use IE to display a countdown, today I am counting down waiting for a special event and I thought why not let PowerShell show me how much time is left so I wrote this little function to show it to me.

Usage: (this special event is at 20:00 in my time zone probably different time for you 😀 )

Show-CountDown "09/09/2014 20:00"

You’ll get:

And the function:

function Show-CountDown([datetime]$TargetDate) { $ie = New-Object -comobject "InternetExplorer.Application" $ie.navigate("about:blank") $ie.top = 10 $ie.left = 10 $ie.height = 120 $ie.width = 260 $ie.toolbar = $false $ie.visible = $true $body = $script:ie.document.body.innerhtml while ((Get-Date) -le $TargetDate) { $TimeLeft = New-TimeSpan -Start (Get-Date) -End $TargetDate $body = "Time left to: $TargetDate<br> Hours: $($TimeLeft.hours) Minutes:$($TimeLeft.minutes) Seconds: $($TimeLeft.Seconds)" $ie.document.body.innerhtml = $body Start-Sleep 0.5 } #Beep twice at the end. [console]::beep(600,400) [console]::beep(600,400) }