Skip to content

Instantly share code, notes, and snippets.

@balazsbotond
Last active April 28, 2024 04:01
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balazsbotond/87ce12b77fbeb742b0663628efb32984 to your computer and use it in GitHub Desktop.
Save balazsbotond/87ce12b77fbeb742b0663628efb32984 to your computer and use it in GitHub Desktop.
PowerShell script for sending Windows 10 notifications
$ErrorActionPreference = "Stop"
$notificationTitle = "Build Succeeded"
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01)
$toastXml = [xml] $template.GetXml()
$toastXml.GetElementsByTagName("text").AppendChild($toastXml.CreateTextNode($notificationTitle)) > $null
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($toastXml.OuterXml)
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
$toast.Tag = "Test1"
$toast.Group = "Test2"
$toast.ExpirationTime = [DateTimeOffset]::Now.AddSeconds(5)
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("Script Completed!")
$notifier.Show($toast);
@probablypablito
Copy link

probablypablito commented Mar 27, 2023

How would you add a picture/icon to the notification?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment