Skip to content

Instantly share code, notes, and snippets.

@bellons91
Created August 2, 2022 07:54
Show Gist options
  • Save bellons91/cd80f658eed28fb9b834f52d53056995 to your computer and use it in GitHub Desktop.
Save bellons91/cd80f658eed28fb9b834f52d53056995 to your computer and use it in GitHub Desktop.
This PowerShell script allows you to show timed notification on your Win10 system. It can be useful to show reminders
function Show-Notification {
[cmdletbinding()]
Param (
[string]
$ToastTitle,
[string]
[parameter(ValueFromPipeline)]
$ToastText
)
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$Template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
$RawXml = [xml] $Template.GetXml()
($RawXml.toast.visual.binding.text|where {$_.id -eq "1"}).AppendChild($RawXml.CreateTextNode($ToastTitle)) > $null
($RawXml.toast.visual.binding.text|where {$_.id -eq "2"}).AppendChild($RawXml.CreateTextNode($ToastText)) > $null
$SerializedXml = New-Object Windows.Data.Xml.Dom.XmlDocument
$SerializedXml.LoadXml($RawXml.OuterXml)
$Toast = [Windows.UI.Notifications.ToastNotification]::new($SerializedXml)
$Toast.Tag = "PowerShell"
$Toast.Group = "PowerShell"
$Toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(1)
$Notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("PowerShell")
$Notifier.Show($Toast);
}
$timer = new-timespan -Hours 6
$clock = [diagnostics.stopwatch]::StartNew()
while ($clock.elapsed -lt $timer){
Show-Notification -ToastTitle "My title" -ToastText "A message that will be displayed"
start-sleep -seconds 300
}
write-host "Timer end"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment