Skip to content

Instantly share code, notes, and snippets.

@Windos
Created May 4, 2023 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Windos/1d8f8f7843a25afd81a19ccc7ff7a2fe to your computer and use it in GitHub Desktop.
Save Windos/1d8f8f7843a25afd81a19ccc7ff7a2fe to your computer and use it in GitHub Desktop.
RTPSUG Actionable Toast Notifications in Windows PowerShell
# Icons care of Wikimedia Commons
# https://commons.wikimedia.org/wiki/File:Circle-icons-chat.svg
# https://commons.wikimedia.org/wiki/File:Pictogram_reply_soft_green_wbg.svg
$ChatIcon = 'C:\Demos\Circle-icons-chat.svg.png'
$ReplyIcon = 'C:\Demos\Pictogram_reply_soft_green_wbg.svg.png'
# Download from here: https://www.nuget.org/packages/Microsoft.Toolkit.Uwp.Notifications/
Add-Type -Path 'C:\Demos\Microsoft.Toolkit.Uwp.Notifications\net461\Microsoft.Toolkit.Uwp.Notifications.dll'
$CompatMgr = [Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]
Register-ObjectEvent -InputObject $CompatMgr -EventName OnActivated -Action {
if ($Event.SourceArgs.UserInput.value -ne '' -and
$Event.SourceArgs.Argument -eq 'Reply') {
$Output = 'User replied @ {0}: {1}' -f [datetime]::Now.ToString('s'),
$Event.SourceArgs.UserInput.value
Write-Warning $Output
}
}
[Microsoft.Toolkit.Uwp.Notifications.ToastContentBuilder]::new().
AddText('New Message from Mr Judd').
AddText("PowerShell Summit was great, but RTPSUG is where it's at.").
AddAppLogoOverride($ChatIcon).
AddAttributionText('via PowerChat').
AddInputTextBox('ConfirmBox', 'Type reply here').
AddButton([Microsoft.Toolkit.Uwp.Notifications.ToastButton]::new().
SetContent('Reply').
AddArgument('Reply').
SetImageUri($ReplyIcon).
SetTextBoxId('ConfirmBox')).
Show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment