Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dagrachon/da3327c01402f5ffd1d7e3cd68a3e237 to your computer and use it in GitHub Desktop.
Save dagrachon/da3327c01402f5ffd1d7e3cd68a3e237 to your computer and use it in GitHub Desktop.
Windows 10 toast notification for WindowsUdateScript
#used in https://github.com/dagrachon/windows_update_script
$ErrorActionPreference = "Stop"
$notificationTitle = "Automatic WindowsUpdate"
$notificationText = "Windows Major Upgrades were found.`r`nPlease go to your update center and install them."
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
$template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText04)
#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("<toast launch='Automatic WindowsUpdate'>
<visual>
<binding template='ToastImageAndText04'>
<text id='1'>$notificationTitle</text>
<text id='2'>$notificationText</text>
<image id='1' src='file:///c:/admin/test.png' />
</binding>
</visual>
<actions>
<action activationType='protocol' content='Update-Center' arguments='ms-settings:windowsupdate' />
<action activationType='system' content='' arguments='snooze' />
</actions>
</toast>")
$toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
$toast.Tag = "WindowsUpdate"
$toast.Group = "WindowsUpdate"
$toast.ExpirationTime = (Get-Date).AddMinutes(10)
$toast.Activated
#$toast.SuppressPopup = $true
$notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($notificationTitle)
$notifier.Show($toast)
@dagrachon
Copy link
Author

Update:
Implemented Notification-Buttons:
Button 1: Opens the Windows-Update Settings
Button 2: Sends the Message to Snooze (With System-Default snooze-timer)

Note: as image i used one of microsofts folder-icons, you can use any picture you want!

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