Words: 367
Time to read: ~ 2 minutes
Link to script: https://github.com/shaneis/RandomScripts/commit/9d6967fa56a75342f00e5ddbcd066adc387f2618
It’s my first SQL Saturday since moving back to Ireland. I figure that it’ll be easier to go to these now that I have a car again and can drive where they are.
The only problem is that this particular SQL Saturday is down in Cork, starting at 08:00 in the morning. That means a 04:30 start for me to get there in time.
Something people may not know about me is that I am not a morning person!
I also like helping out so for the very first session I was given the task of letting the speaker know how much time that they had left for their session.
So there’s me in the corner, holding up laminated pages with the number 30, 15, 10, and 5 in big, bold font on them and holding them up when time passed.
Thankfully the speaker was engaging and enthusiastic, and the session was new and interesting to me because otherwise I was freaking out that I would fall asleep and fail to actually do anything!
This got me thinking if there was anyway to automate myself out of this equation…
Get-SpeakerTimeNotification
I’ve been tuning in to Joshua King’s YouTube streams ( blog | twitter | YouTube ) lately and he has been working on his Burnt Toast module.
It’s really interesting and I’ve been looking for an opportunity to use it; this defintiely counts!
So I created a function use Burnt Toast to pop up a notification in the bottom corner of the screen after a set amount of time.
So for SQL Saturday Cork, all we’d need to do is run the following code in a new PowerShell console on the speakers laptop and they’d get a notification after 30 minutes, 15 minutes after that, 10 minutes after that, and 5 minutes after that with a final notification after that saying “TIME!”
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-SpeakerTimeNotification –CountdownMinutes 30, 15, 10, 5 –FinalNotification |
Going Forward
The script is up on my github, and there’s so much to improve upon it.
- Ability to run this in the background;
- Create proper Pester tests;
- Proper verbose output and debugging output; and
- Ensure all the dependencies are there before running the script.
Here’s a gist of the script in the meantime before improvements take place:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-SpeakerTimeNotification { | |
[CmdletBinding()] | |
<# | |
.SYNOPSIS | |
Creates notifications after specified minutes | |
.DESCRIPTION | |
Uses the BurntToast module to create notifications for the user after a supplied number | |
of minutes have passed. These can be sorted and a final notification can be given that | |
just specifies "TIME!" | |
.EXAMPLE | |
PS C:\> Get-SpeakerTimeNotification -CountdownMinutes 30, 15, 10, 5 | |
Creates a notification after 30 minutes, 15 minutes, 10 minutes, 5 minutes. | |
.EXAMPLE | |
PS C:\> Get-SpeakerTimeNotification 1, 2 -Sort | |
Sorts the minutes first so the notification appears after 2 minutes then 1 minute. | |
.EXAMPLE | |
PS C:\> Get-SpeakerTimeNotification 1, 2 -Sort -Verbose -FinalNotification | |
Sorts the minutes first so the notification appears after 2 minutes then 1 minute. | |
Creates a final notification after an extra minute saying "TIME!". | |
.INPUTS | |
[int[]] | |
.OUTPUTS | |
Burnt Toast Notification | |
.NOTES | |
General notes | |
#> | |
param ( | |
# a list of minutes to notify the speaker when they have elapsed. | |
[Parameter(Mandatory, | |
ValueFromPipelineByPropertyName, | |
Position = 0, | |
HelpMessage = 'List of minutes to notify the speaker after')] | |
[int[]]$CountdownMinutes, | |
# switch to see if you want the minutes sorted largest to smallest. | |
[switch]$Sort, | |
# switch to see if you want a final "TIME!" notification. If the "Sorted" switch is specified, | |
# will use the smallest input time. Otherwise uses the last inputted time. | |
[switch]$FinalNotification | |
) | |
begin { | |
$stopWatch = [System.Diagnostics.Stopwatch]::new() | |
if ($Sort) { | |
$CountdownMinutes = $CountdownMinutes | Sort-Object –Descending | |
} | |
Write-Verbose "FinalNotification: $FinalNotification" | |
if ($FinalNotification) { | |
if ($Sort) { | |
$finalTime = ($CountdownMinutes | Sort-Object –Descending)[-1] | |
} else { | |
$finalTime = $CountdownMinutes[-1] | |
} | |
} | |
Write-Verbose "FinalNotification: $FinalNotification" | |
} | |
process { | |
$stopWatch.Start() | |
foreach ($time in $CountdownMinutes) { | |
do { | |
Start-Sleep –Seconds 60 | |
$VerboseMessage = [PSCustomObject]@{ | |
MinutesElapsed = $stopWatch.Elapsed.TotalMinutes | |
TimeWaitingFor = $time | |
} | |
Write-Verbose $VerboseMessage | |
} until ($stopWatch.Elapsed.TotalMinutes -ge $time) | |
$text = "$time minutes left!" | |
if ($time -eq 1) { | |
$text = "$time minute left!" | |
} | |
New-BurntToastNotification –Text $text | |
$stopWatch.Restart() | |
} | |
if ($finalTime) { | |
Start-Sleep –Seconds ($finalTime * 60) # seconds, not minutes… | |
New-BurntToastNotification –Text 'TIME!' | |
} | |
} | |
end { | |
$stopWatch.Stop() | |
} | |
} |
2 thoughts on “Automating Conference Speaker Notifications”