Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / PowerShell / How Show a Pop-Up or Balloon Notification with PowerShell

April 10, 2024 PowerShellWindows 10Windows 11Windows Server 2022

How Show a Pop-Up or Balloon Notification with PowerShell

You can use PowerShell to show pop-up or toast messages to notify Windows users about important events. To get information from the user or confirm an action, you can use PowerShell to display toast (pup-up) notifications or modal dialog boxes.

Contents:
  • Display a Pop-Up Message with PowerShell
  • Send a Toast Notification from PowerShell Script
  • Showing a Pop-Up Message on Remote Computer Using PowerShell

Display a Pop-Up Message with PowerShell

If you want to display a simple modal dialogue box on a desktop, you can use the Wscript class. To display a pop-up window with your message text and the OK button, use the following PowerShell code:

$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 the various properties of the Popup method, you can customize the appearance of this modal window and add action buttons to it.  For example, to display a pop-up prompt with Yes and No buttons, run:

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

$Output = $wshell.Popup("The script completed successfully. Do you want to view a report?",0,"The report is ready",4+32)

If the user clicks Yes, the command returns 6, and if No, it returns 7. You can run an action or exit the script, depending on the user’s choice.

switch ($Output) { 
    7 {$wshell.Popup('Pressed No')} 
    6 {$wshell.Popup('Pressed Yes')} 
    default {$wshell.Popup('Invalid input')} 
}

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). Number of seconds before the message window closes automatically;
  • <Title> —string (optional). The title text (caption) of the pop-up window;
  • <Type> —number (optional). A combination of flags that determine the type of buttons and icons.

Possible values for the Type flag:

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

The Popup method returns an integer value that allows you to know which button a user has clicked. 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.

Use the Windows Forms class when you need to prompt the user for information.

Add-Type -AssemblyName System.Windows.Forms
$input = [Microsoft.VisualBasic.Interaction]::InputBox("Enter your username:", " Require user input", "")

To process user input:

if ([string]::IsNullOrWhiteSpace($input)) {
  Write-Host " No information provided"
} else {
    Write-Host " You have entered $input"
}

PowerShell show GUI input box

If you want to display a modal dialogue on top of all windows on the desktop:

($ModalTop = New-Object 'System.Windows.Forms.Form').TopMost = $True
[System.Windows.Forms.MessageBox]::Show($ModalTop,"Your text", " Your Caption", 4, 48)

Send a Toast Notification from PowerShell Script

Use the Windows Forms class to display more attractive toast (balloon) notifications. The following PowerShell code displays a pop-up message next to the Windows notification bar that disappears after 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 a pop-up message text for the Windows user'
$balmsg.BalloonTipTitle = "Attention $Env:USERNAME"
$balmsg.Visible = $true
$balmsg.ShowBalloonTip(20000)

balloon tip notification with PowerShell in windows 10

To create PowerShell pop-up notifications in Windows, you can use the third-party BurntToast module from the PowerShell gallery. Install the module:

Install-Module -Name BurntToast

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

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

Show toast notification from a PowerShell script

Showing a Pop-Up Message on Remote Computer Using PowerShell

You can use PowerShell to send a toast message to a user on a remote computer. First, list the user sessions on the remote computer (in the case of an RDS server):

qwinsta /server:Mun-RDS1

To send a pop-up message to a specific user session on a remote computer:

MSG jsmith /server:Mun-RDS1 "Please restart the SUPGUI client in 5 minutes!”

If you want to send a popup message to all users, use * instead of the username:

MSG * /server:Mun-RDS1 " The server will be restarted in 10 minutes. Save your files and open documents!"

msg command to send message to all users on remote machine

To send a pop-up graphical notification to a remote computer, you can use the RemoteSendToasNotification.ps1 script from our GitHub repo ( https://github.com/maxbakhub/winposh/blob/main/WindowsDesktopManagement/RemoteSendToasNotification.ps1). The Invoke-Command cmdlet that is used to establish the connection requires that WinRM be enabled and configured on the remote computer.

Send toast notification to remote computer with Invoke-Command

2 comments
4
Facebook Twitter Google + Pinterest
previous post
How to Import and Export Mailbox to PST in Exchange 2019/2016/2013
next post
Fix RDP Authentication Error: The Function Requested Is Not Supported

Related Reading

Configure NTP Time Source for Active Directory Domain

May 6, 2025

How to Cancel Windows Update Pending Restart Loop

May 6, 2025

View Windows Update History with PowerShell (CMD)

April 30, 2025

Cannot Install Network Adapter Drivers on Windows Server

April 29, 2025

Change BIOS from Legacy to UEFI without Reinstalling...

April 21, 2025

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

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

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

  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025
  • How to Write Logs to the Windows Event Viewer from PowerShell/CMD

    March 3, 2025
  • How to Hide (Block) a Specific Windows Update

    February 25, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Managing Printers and Drivers on Windows with PowerShell
  • Protecting Remote Desktop (RDP) Host from Brute Force Attacks
  • How to Set a User Thumbnail Photo in Active Directory
  • Match Windows Disks to VMWare VMDK Files
  • Implementing Dynamic Groups in Active Directory with PowerShell
  • FTP Server Quick Setup on Windows 10/11 and Windows Server
  • How to View and Close Open Files on Windows Server
Footer Logo

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


Back To Top