Skip to content

Instantly share code, notes, and snippets.

@mikeslattery
Last active February 20, 2020 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeslattery/f75107b51de120d0c373b29c43b6daf5 to your computer and use it in GitHub Desktop.
Save mikeslattery/f75107b51de120d0c373b29c43b6daf5 to your computer and use it in GitHub Desktop.
Windows Notification Toast
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