How to show Toast Notifications for failing Event scripts

By default powerEvents informs Vault users via Message Box when event scripts can not be executed or registered Event actions suddenly terminate with Errors. The Message Box needs input from the user to be dismissed.

This behavior can be changed to use Toast Notifications that do not need input from the user.

Install the BurntToast module

The BurntToast powerShell module requires Windows 8 or higher because the module makes use of the Action Center.

You can install the module by opening the PowerShell Console as Administrator and executing following command:

Install-Module -Name BurntToast
 

If this does not work it is possible to install the module manually by following the instructions on GitHub.

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

Showing ToastNotifications for Terminaing Errors

To change the error behavior of powerEvents for all event scripts copy the following code into a new Module called "ToastNotifications.psm1" located in "C:\ProgramData\coolOrange\powerEvents\Modules".

This example shows how to set up a Toast Notifications with the New-BurntToastNotification commandlet by overriding the OnTerminatingError property of the powerEvents $Host:

Import-Module BurntToast

$global:Host.PrivateData.OnTerminatingError = {
param($exception)
$openLogFolderBtn = New-BTButton -Content "Open Log" -Arguments "$($env:LOCALAPPDATA)\coolOrange\powerEvents\Logs"
New-BurntToastNotification -Text "powerEvents ran into an error ", "'$($exception.Message)'", "Open the logfile for more information" -Button $openLogFolderBtn
}
Afterwards all terminating powerShell Errors will show non-blocking ToastNotifications with the Exception message and also a button to access the powerEvents Logs directory.

See Also