For a user it could be helpful to get notifications on different things that are happening in the background


Install the module

Check your powerShell version:


If you have powerShell 5 or higher open the powerShell as an administrator, type following command and follow the instructions to install the module:

Install-Module -Name BurntToast

If you have a powerShell version earlier than 5 follow the instructions on GitHub to manually install the module.

Using the module

After installation the cmdlets are available by default in every powerShell session.

Simple notification

To show a simple notification use following sample code. The values separated by commas in the -Text parameter are shown in different lines. You can add a maximum of 3 lines per notification:

$title = "My first notification"
$text = "Hello World"
New-BurntToastNotification -Text @($title, $text)

Notification with a button

It is possible to add a button in the notification. The button has an argument that is able to do different things. In this example it opens the directory of the powerEvents logfile. This can be useful in case of errors.

$openLogFolderBtn = New-BTButton -Content "Open Log folder" -Arguments "$($env:LOCALAPPDATA)\coolOrange\powerEvents\Logs"
$title = "Error happened while executing event"
$text = "Look in the logfile for more information"
New-BurntToastNotification -Text @($title, $text) -Button $openLogFolderBtn

This code can be implemented in specific locations e.g. if a check goes wrong or if there is an error while executing an event.

if ($file.State -eq "Released) {
   # your code
} else {
  # Show a notification

In a try catch the code that is placed in "try" is executed and in case of errors the "catch" block is executed. In the catch block the variable "$_" is available and contains the error message.

try {
    # Your code
} catch {
    $openLogFolderBtn = New-BTButton -Content "Open Log folder" -Arguments "$($env:LOCALAPPDATA)\coolOrange\powerEvents\Logs"
    $title = "Exception happened while executing event"
    $exception = $_.Exception.Message
    New-BurntToastNotification -Text @($title, $exception) -Button $openLogFolderBtn   

See Also

BurntToast Help section (gitHub)

try catch finally (Windows docs)