Last active
February 20, 2020 18:02
-
-
Save mikeslattery/f75107b51de120d0c373b29c43b6daf5 to your computer and use it in GitHub Desktop.
Windows Notification Toast
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 notify($notificationTitle) { | |
$app = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe' | |
[void][Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | |
# Fetch empty template | |
$templateType = [Windows.UI.Notifications.ToastTemplateType]::ToastText01 | |
$template = [xml]([Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($templateType).getXml()) | |
#Convert to .NET type for XML manipuration | |
[void]$template.GetElementsByTagName("text").AppendChild($template.CreateTextNode($notificationTitle)) | |
#Convert back to WinRT type | |
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument | |
$xml.LoadXml($template.OuterXml) | |
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml) | |
$toast.Tag = "PowerShell" | |
$toast.Group = "PowerShell" | |
$toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(5) | |
#$toast.SuppressPopup = $true | |
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($app) | |
$notifier.Show($toast) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment