-
-
Save Nevember/13241c30d4cce44f403af71bb60a263a to your computer and use it in GitHub Desktop.
Toast Notification in PowerShell
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 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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment