Changing icons and hover text in PowerShell tray applications

We have recently been asked how the tray icon of a script packaged with PowerShell Studio or PrimalScript can be changed dynamically. This requires access to the NotifyIcon object, which was previously not accessible from the PowerShell code within a packaged application.

With PowerShell Studio 2025 (5.9.255) and PrimalScript 2025 (8.1.217) this is now available to modify hover text and icons. We have updated the sample included with the custom menu blog post with code illustrating this.

image

The $SAPIENHost variable has three additional member functions:

1. SetNotifyiconIcon(int index)

This function changes the icon displayed in the system tray dynamically. The index is the 0 based position in the icons specified when packaging.

image

2. SetNotifyiconText(string text)

When hovering with the mouse over a tray application, a tooltip is displayed. Previously this defaulted to the application name but can now be modified within the packaged script.

image

3. NotifyIcon GetNotifyIconObject()

You can also now retrieve the NotifyIcon object itself if you want to access additional properties. This might be useful for loading custom icons not embedded in the packaged executable.

These functions are available through the $SAPIENHost variable in tray applications packaged for Windows PowerShell, PowerShell 7.4.7, and 7.5.0 or later. Other SAPIEN engines (except console apps) and the debugger have these functions stubbed out, but return null and otherwise are non-operational.

Download

You can download the modified sample here.

You will need PowerShell Studio 2025 (5.9.255) or PrimalScript 2025 (8.1.217) or any later version of either product.

Feedback

As always, if you have any ideas, comments, or feedback, please use our feedback forum and reference this post.