-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-SpeakerTimeNotification.ps1
103 lines (81 loc) · 3.13 KB
/
Get-SpeakerTimeNotification.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
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()
}
}