Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Windows 10 toast notification sample
$ErrorActionPreference = "Stop"
$notificationTitle = "Notification: " + [DateTime]::Now.ToShortTimeString()
[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
$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("PowerShell")
Copy link

guillaume86 commented Jul 6, 2016


Copy link

sheldonhull commented Jul 15, 2016

very useful, thanks!

Copy link

guillaume86 commented Jul 20, 2016

An idea to workaround the "Windows PowerShell cannot subscribe to Windows RT events" error when trying to subscribe to the Activated event of the toast?

Copy link

potatoqualitee commented Feb 14, 2017

awesome! thanks

Copy link

KnorxThieus commented May 20, 2017

How can I avoid the toast will be deleted after 6 seconds no matter what expiration time is setted? :(

Copy link

dagrachon commented Jun 28, 2017

nice work, thank you!

Copy link

xCONFLiCTiONx commented Dec 22, 2017

This doesn't work for me for some reason. No error either. I have latest version of Windows 1709 16299.125 completely up-to-date.

Copy link

steepedteait commented Jan 3, 2018

I have the same issue, this appears to be broken as of 1709

Copy link

guillaume86 commented Feb 5, 2018

Yes it's broken now, if anyone found an alternative I'm interested :)

Edit: found the solution, use a real AppId, example here:

explanation here:

Copy link

KirillOsenkov commented Aug 24, 2018

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