Popup Power
In this issue:
Most of the time, when we run PowerShell code, everything stays in the console. We input things via command parameters and output typically goes to the PowerShell host to be viewed or consumed by other commands in the PowerShell pipeline. However, depending on your code and scenario, you may have other interaction needs. Maybe you want to display an alert that a long running PowerShell command has completed. Or provide a visual prompt for user input. There are a few tools at your disposal to help with this. Let's begin with the BurntToast module.
Burnt Toast
On Windows platforms you've likely seen the toast notifications that pop up in the lower right corner of your screen. These are typically used by applications to provide alerts or other information. The BurntToast PowerShell module allows you to create and display these toast notifications from PowerShell. You can install the module from the PowerShell Gallery:
Install-PSResource BurntToast
The module was recently updated so make sure you are installing v1.1.0 or later. Using Get-ModuleCommand
from the PSScriptTools module, you can see the commands available in the BurntToast module:
PS C:\> Get-ModuleCommand BurntToast
ModuleName: BurntToast [v1.1.0]
Name Alias Synopsis
---- ----- --------
Get-BTHeader Shows and filters all toast notification headers in the Action...
Get-BTHistory Shows all toast notifications in the Action Center or scheduled ...
New-BTAction Creates an action set for a Toast Notification.
New-BTAudio Creates a new Audio object for Toast Notifications.
New-BTBinding Creates a new Generic Toast Binding object.
New-BTButton Creates a new clickable button for a Toast Notification.
New-BTColumn Creates a new column (Adaptive Subgroup) for Toast Notifications.
New-BTContent Creates a new Toast Content object (base element for displaying ...
New-BTContextMenuItem Creates a Context Menu Item object.
New-BTHeader Creates a new toast notification header.
New-BTImage Creates a new Image Element for Toast Notifications.
New-BTInput Creates an input element (text box or selection box) for a Toast...
New-BTProgressBar Creates a new Progress Bar element for Toast Notifications.
New-BTSelectionBoxItem Creates a selection box item for use in a toast input.
New-BTShortcut Creates a Windows shortcut for launching PowerShell or a compat...
New-BTText Creates a new text element for Toast Notifications.
New-BTVisual Creates a new visual element for toast notifications.
New-BurntToastNotification Toast Creates and displays a rich Toast Notification for Windows.
Remove-BTNotification Removes toast notifications from the Action Center.
Submit-BTNotification Submits a completed toast notification for display.
Update-BTNotification Updates an existing toast notification.
I'm not going to cover every command. I'll focus on the command you are likely to use the most, New-BurntToastNotification
, which has an alias of toast. I'll use the alias in my example for the sake of brevity.
Creating a basic toast notification is as simple as running the following command:
Toast -Text 'Pay attention to me'

Be aware that the first time you send a toast notification from PowerShell, Windows will prompt you to allow PowerShell to send notifications. You must allow this for all subsequent notifications to appear.
Adding a Header
You can add a title to the notification by using the -Header
parameter:
$h = New-BTHeader -Title 'PS Toast'
Toast -Text 'Pay attention to me' -Header $h

The text "field" appears to be about 6 lines and will be treated as strings.
$body = @"
Here is the information you requested.
$(($PSVersionTable | Out-String).Trim())
"@
Toast -Text $body -Header $h

Notice the font is not monospaced so don't expect nice table formatting. I'm not aware of any way to change the font used in the notification.
With some trial and error, it is possible to get a bit more control over the formatting.
$body= @"
PSVersion = $($PSVersionTable.PSVersion)
PSEdition = $($PSVersionTable.PSEdition)
Platform = $($PSVersionTable.Platform)
Computername = $Env:Computername
"@
Toast -Text $body -Header $h -Urgent