Forked from altrive/ToastNotification_Windows10.ps1
Last active
July 3, 2017 11:21
-
-
Save dagrachon/da3327c01402f5ffd1d7e3cd68a3e237 to your computer and use it in GitHub Desktop.
Windows 10 toast notification for WindowsUdateScript
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
#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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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!