Advertisement
Flimbot

Add-WindowsNotification

Feb 19th, 2020
1,489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function Add-WindowsNotification{
  2.     Param(
  3.         [parameter(Mandatory=$true)][ValidatePattern('^[\w\-]+$')][String]$AppId,
  4.         [parameter(Mandatory=$true)][ValidateLength(1,108)][String]$Message
  5.     )
  6.  
  7.    
  8.     $notificationTemplate = [Windows.UI.Notifications.ToastTemplateType]::ToastText01
  9.  
  10.     $notification = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent($notificationTemplate)
  11.     $textElement = $notification.SelectSingleNode('/toast/visual/binding/text')
  12.     $textElement.innerText = $message
  13.     $notificationInstance = New-Object Windows.UI.Notifications.ToastNotification $notification
  14.     $notificationManager = [Windows.UI.Notifications.ToastNotificationManager]::GetDefault()
  15.     $notifier = $notificationManager.CreateToastNotifier($AppId)
  16.     $notifier.show($notificationInstance)
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement