Skip to content

Instantly share code, notes, and snippets.

@mattbalzan
Created January 6, 2025 10:52
Show Gist options
  • Save mattbalzan/ef27f1d93c9dd8c39cde472a9b6e08cd to your computer and use it in GitHub Desktop.
Save mattbalzan/ef27f1d93c9dd8c39cde472a9b6e08cd to your computer and use it in GitHub Desktop.
Windows Toast Message
# --[ Windows Toast Message ]
# --[ Matt Balzan | mattGPT.co.uk ]
function Toast($Title,$msgText){
# Main script
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.UI.Notifications.ToastNotification, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
[Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
$APP_ID = '{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\WindowsPowerShell\v1.0\powershell.exe'
$template = @"
<toast>
<visual>
<binding template="ToastText02">
<text id="1">$Title</text>
<text id="2">$msgText</text>
</binding>
</visual>
</toast>
"@
$xml = New-Object Windows.Data.Xml.Dom.XmlDocument
$xml.LoadXml($template)
$toast = New-Object Windows.UI.Notifications.ToastNotification $xml
[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($APP_ID).Show($toast)
}
Toast Hello Howdy!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment