Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / PowerShell / How to Show a Pop-Up or Balloon Tip Notification from PowerShell?

May 10, 2023 PowerShellWindows 10Windows Server 2016

How to Show a Pop-Up or Balloon Tip Notification from PowerShell?

Although PowerShell is a console language, sometimes it is necessary to notify a user from a PS script about a particular event or prompt them to do something. For example, you can display a pop-up notification or balloon tip about the completion of a heavy PoSh script or when an important event occurs.

The easiest way is to display a window containing any text using the Windows script subsystem (Wscript) call from PowerShell.

This PowerShell code will show a common window with your message and the OK button.

$wshell = New-Object -ComObject Wscript.Shell
$Output = $wshell.Popup("The report generation script is successfully completed!")

Wscript - powershell show a windows with the notification

Using different properties of the Popup method, you can customize the appearance of the modal window containing your message text. You can also return to the script the user’s answer (Yes/No).

display a pop-up message box with PowerShell with yes/no

$Output = $wshell.Popup("The report generation script is successfully completed! Do you want to display a report on the screen?",0,"The report is ready",4+32)

The general syntax and the available parameters of the Popup method:

Popup(<Text>,<SecondsToWait>,<Title>,<Type>)

Parameters:

  • <Text> — a message text (string);
  • <SecondsToWait> — a number (optional). The number of seconds after which the message window will be automatically closed;
  • <Title> —string (optional). The title text (caption) of the pop-up window;
  • <Type> —number (optional). The combination of flags that determines the type of buttons and icons.

Possible Type flag values:

    • 0 — OK button;
    • 1 — OK and Cancel buttons;
    • 2 — Stop, Retry and Skip buttons;
    • 3 — Yes, No and Cancel buttons;
    • 4 — Yes and No buttons;
    • 5 — Retry and Cancel buttons;
    • 16 — Stop icon;
    • 32 — Question icon;
    • 48 — Exclamation icon;
    • 64 — Information icon.

The Popup method returns an integer that allows to know, which button was clicked by a user. Possible values:

  • -1 — timeout;
  • 1 — OK button;
  • 2 — Cancel button;
  • 3 — Stop button;
  • 4 — Retry button;
  • 5 — Skip button;
  • 6 — Yes button;
  • 7 — No button.

More attractive pop-up messages (balloon tips) may be displayed in Windows 7, 8.1 & 10 through the Windows Forms API. The following PowerShell code will show a pop-up message next to the Windows 10 Notification bar that will automatically disappear in 20 seconds.

Add-Type -AssemblyName System.Windows.Forms
$global:balmsg = New-Object System.Windows.Forms.NotifyIcon
$path = (Get-Process -id $pid).Path
$balmsg.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balmsg.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
$balmsg.BalloonTipText = ‘This is the pop-up message text for the Windows 10 user'
$balmsg.BalloonTipTitle = "Attention $Env:USERNAME"
$balmsg.Visible = $true
$balmsg.ShowBalloonTip(20000)

balloon tip notification with PowerShell in windows 10

To create colorful pop-up messages in Windows 10 (PowerShell 5.0+), you can also use a separate PowerShell module BurntToast from the PowerShell gallery.

The module is installed from the online repository using the command:
Install-Module -Name BurntToast

For example, now you can easily add a colorful notification to the script from the article “How to automatically disable Wi-Fi when Ethernet cable is connected”:

New-BurntToastNotification -Text "Disconnecting from Wi-Fi network", "You have been disconnected from your Wi-Fi network since your device was connected to a high-speed Ethernet LAN" -AppLogo C:\PS\changenetwork.png

Therefore, you know how to display a notification to a user with PowerShell. If a user has speakers, you can even play the favorite melody:

[console]::beep(440,500)
[console]::beep(440,500)
[console]::beep(440,500)
[console]::beep(349,350)
[console]::beep(523,150)
[console]::beep(440,500)
[console]::beep(349,350)
[console]::beep(523,150)
[console]::beep(440,1000)
[console]::beep(659,500)
[console]::beep(659,500)
[console]::beep(659,500)
[console]::beep(698,350)
[console]::beep(523,150)
[console]::beep(415,500)
[console]::beep(349,350)
[console]::beep(523,150)
[console]::beep(440,1000)
[console]::beep(880,500)
[console]::beep(440,350)
[console]::beep(440,150)
[console]::beep(880,500)
[console]::beep(830,250)
[console]::beep(784,250)
[console]::beep(740,125)
[console]::beep(698,125)
[console]::beep(740,250)
[console]::beep(455,250)
[console]::beep(622,500)
[console]::beep(587,250)
[console]::beep(554,250)
[console]::beep(523,125)
[console]::beep(466,125)
[console]::beep(523,250)
[console]::beep(349,125)
[console]::beep(415,500)
[console]::beep(349,375)
[console]::beep(440,125)
[console]::beep(523,500)
[console]::beep(440,375)
[console]::beep(523,125)
[console]::beep(659,1000)
[console]::beep(880,500)
[console]::beep(440,350)
[console]::beep(440,150)
[console]::beep(880,500)
[console]::beep(830,250)
[console]::beep(784,250)
[console]::beep(740,125)
[console]::beep(698,125)
[console]::beep(740,250)
[console]::beep(455,250)
[console]::beep(622,500)
[console]::beep(587,250)
[console]::beep(554,250)
[console]::beep(523,125)
[console]::beep(466,125)
[console]::beep(523,250)
[console]::beep(349,250)
[console]::beep(415,500)
[console]::beep(349,375)
[console]::beep(523,125)
[console]::beep(440,500)
[console]::beep(349,375)
[console]::beep(261,125)
[console]::beep(440,1000)

2 comments
1
Facebook Twitter Google + Pinterest
previous post
Configuring Anti-Spam Protection on Exchange 2013, 2016 – RBL Providers
next post
Fix: The Local Print Spooler Service Not Running in Windows 10

Related Reading

How to Connect VPN Before Windows Logon

November 14, 2023

Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

November 7, 2023

Send Emails with Microsoft Graph API and PowerShell

November 6, 2023

Zabbix: How to Get Data from PowerShell Scripts

October 27, 2023

Tracking Printer Usage with Windows Event Viewer Logs

October 19, 2023

2 comments

Vandrey Trindade July 2, 2019 - 6:01 pm

The ballon tooltip seems very nice. But it adds an icon to the toolbar and you have to run a code to kill it:
$script:balmsg.Dispose()
The problem is that you don’t know if the user saw the notification… So you don’t have a way to know when to kill that icon.
And if you don’t kill it, the user must close PowerShell to get rid of that icon…

Reply
Fer September 19, 2021 - 1:12 pm

Thank you! Really useful

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • How to Connect VPN Before Windows Logon

    November 14, 2023
  • Removing Azure Arc Setup Feature on Windows Server 2022

    November 9, 2023
  • Using WPAD (Web Proxy Auto-Discovery Protocol) on Windows

    November 7, 2023
  • Send Emails with Microsoft Graph API and PowerShell

    November 6, 2023
  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Managing Printers and Drivers with PowerShell in Windows 10 / Server 2016
  • Deploy PowerShell Active Directory Module without Installing RSAT
  • Managing User Photos in Active Directory Using ThumbnailPhoto Attribute
  • RDP Brute Force Protection with PowerShell and Windows Firewall Rules
  • Active Directory Dynamic User Groups with PowerShell
  • Match Windows Disks to VMWare VMDK Files
  • Auditing Weak Passwords in Active Directory
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top