Skip to content

Instantly share code, notes, and snippets.

Created March 17, 2021 11:36
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Rough mock-up of actionable toasts in PowerShell 5.1
Add-Type -Path 'C:\temp\microsoft.toolkit.uwp.notifications.7.0.0\lib\net461\Microsoft.Toolkit.Uwp.Notifications.dll'
$CompatMgr = [Microsoft.Toolkit.Uwp.Notifications.ToastNotificationManagerCompat]
Register-ObjectEvent -InputObject $CompatMgr -EventName OnActivated -Action {
if ($Event.SourceArgs.Argument -eq 'SubmitButton') {
switch ($Event.SourceArgs.UserInput.Value) {
Item1 {
$Text1 = 'GIF: Picard Facepalm'
$ImagePath = 'C:\Demos\Gifs\facepalm.gif'
Item2 {
$Text1 = 'GIF: Get It Girl'
$ImagePath = 'C:\Demos\Gifs\get-it-girl.gif'
Item3 {
$Text1 = 'GIF: Seinfeld - Oh, right right right'
$ImagePath = 'C:\Demos\Gifs\oh-right.gif'
Item4 {
$Text1 = 'GIF: Bob Ross?'
$ImagePath = 'C:\Demos\Gifs\bob-ross.gif'
$ContentBuilder = [Microsoft.Toolkit.Uwp.Notifications.ToastContentBuilder]::new()
$null = $ContentBuilder.AddText($Text1)
$null = $ContentBuilder.AddAppLogoOverride('C:\Program Files\PowerShell\7-preview\assets\Powershell_av_colors.ico', 'None')
$null = $ContentBuilder.AddHeroImage($ImagePath)
$null = $ContentBuilder.SetToastDuration('Long')
$null = $ContentBuilder.AddAudio($null, $null, $true)
$ContentBuilder = [Microsoft.Toolkit.Uwp.Notifications.ToastContentBuilder]::new()
$null = $ContentBuilder.AddText('New Batch of Gifs')
$null = $ContentBuilder.AddAppLogoOverride('C:\Program Files\PowerShell\7-preview\assets\Powershell_av_colors.ico', 'None')
$Choices = @()
$Choices += [ValueTuple[string, string]]::new('Item1', 'Picard Facepalm')
$Choices += [ValueTuple[string, string]]::new('Item2', 'Get It Girl')
$Choices += [ValueTuple[string, string]]::new('Item3', 'Seinfeld - Oh, right right right')
$Choices += [ValueTuple[string, string]]::new('Item4', 'Bob Ross?')
$null = $ContentBuilder.AddComboBox('Selection001', 'Select a GIF to view now', 'Item1', $Choices)
$null = $ContentBuilder.AddButton('Submit', 'Background', 'SubmitButton')
$null = $ContentBuilder.AddButton([Microsoft.Toolkit.Uwp.Notifications.ToastButtonDismiss]::new())
Copy link

Did you ever work out how to get the selection choice back as a variable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment