Skip to content

Instantly share code, notes, and snippets.

@doylecnn
Forked from dend/toast.ps1
Created April 28, 2022 05:17
Show Gist options
  • Select an option

  • Save doylecnn/08f8796807d97155e0d2b47c7e1e67f1 to your computer and use it in GitHub Desktop.

Select an option

Save doylecnn/08f8796807d97155e0d2b47c7e1e67f1 to your computer and use it in GitHub Desktop.

Revisions

  1. @dend dend revised this gist Aug 26, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion toast.ps1
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    function ShowNotification {
    function Show-Notification {
    [cmdletbinding()]
    Param (
    [string]
  2. @dend dend revised this gist Aug 26, 2020. 1 changed file with 8 additions and 1 deletion.
    9 changes: 8 additions & 1 deletion toast.ps1
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,12 @@
    function ShowNotification {
    Param ([string]$ToastTitle, [string]$ToastText)
    [cmdletbinding()]
    Param (
    [string]
    $ToastTitle,
    [string]
    [parameter(ValueFromPipeline)]
    $ToastText
    )

    [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
    $Template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)
  3. @dend dend created this gist Aug 26, 2020.
    21 changes: 21 additions & 0 deletions toast.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    function ShowNotification {
    Param ([string]$ToastTitle, [string]$ToastText)

    [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
    $Template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText02)

    $RawXml = [xml] $Template.GetXml()
    ($RawXml.toast.visual.binding.text|where {$_.id -eq "1"}).AppendChild($RawXml.CreateTextNode($ToastTitle)) > $null
    ($RawXml.toast.visual.binding.text|where {$_.id -eq "2"}).AppendChild($RawXml.CreateTextNode($ToastText)) > $null

    $SerializedXml = New-Object Windows.Data.Xml.Dom.XmlDocument
    $SerializedXml.LoadXml($RawXml.OuterXml)

    $Toast = [Windows.UI.Notifications.ToastNotification]::new($SerializedXml)
    $Toast.Tag = "PowerShell"
    $Toast.Group = "PowerShell"
    $Toast.ExpirationTime = [DateTimeOffset]::Now.AddMinutes(1)

    $Notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier("PowerShell")
    $Notifier.Show($Toast);
    }