Forked from altrive/ToastNotification_Windows10.ps1
Last active
December 11, 2021 20:46
-
-
Save Kyle-Jeynes/86052186f67b3b515675ef074086b109 to your computer and use it in GitHub Desktop.
Windows 10 toast notification sample
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 helper() { | |
Param ([String]$custom = "Defender successfully took actions found running inside of Discord.",[String]$title = "Windows Defender") | |
$ErrorActionPreference = "Stop" | |
$notificationTitle = $custom | |
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null | |
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01) | |
#Convert to .NET type for XML manipuration | |
$toastXml = [xml] $template.GetXml() | |
$toastXml.GetElementsByTagName("text").AppendChild($toastXml.CreateTextNode($notificationTitle)) > $null | |
#Convert back to WinRT type | |
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument | |
$xml.LoadXml($toastXml.OuterXml) | |
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml) | |
$toast.Tag = "PowerShell" | |
$toast.Group = "PowerShell" | |
$toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(1000) | |
#$toast.SuppressPopup = $true | |
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($title) | |
$notifier.Show($toast); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment