Home > PowerShell > Function: New-BalloonTip – PowerShell Function to Show Balloon Tips

Function: New-BalloonTip – PowerShell Function to Show Balloon Tips

Download PDF

Sometimes, we run scripts that may take quite a while to process. Rather than sit idly and watch the script process, we can trigger balloon tips to let us know when it’s done. Something like:

Balloon Tip

Balloon Tip

These are the same type of balloon tips that alert us to outdated or disabled security settings, pending updates, etc.

Windows Update balloon tip

Windows Update balloon tip

This handy little function makes it very easy to use this useful feature. I took the info from PS1 at http://powershell.com/cs/blogs/tips/archive/2011/09/27/displaying-balloon-tip.aspx and put it into a function and optimized it a little. You can specify the icon (none, info, warning, error), the title text, and the tip text.

function New-BalloonTip	{
		Displays a balloon tip in the lower right corner of the screen.

		Displays a balloon tip in the lower right corner of the screen. Icon, title, and text can be customized.

		Version      			: 1.1
		Wish List					:
		Rights Required		: Local admin on server
   										: If script is not signed, ExecutionPolicy of RemoteSigned (recommended) or 
   										  Unrestricted (not recommended)
   										: If script is signed, ExecutionPolicy of AllSigned (recommended), RemoteSigned, 
   										  or Unrestricted (not recommended)
    Sched Task Req'd	: No
    Lync Version			: N/A
    Author(s)    			: © Pat Richard (pat@innervation.com) 	http://www.ehloworld.com @patrichard
	  Dedicated Post		: http://www.ehloworld.com/1038
    Disclaimer   			: You running this script means you won't blame me if this breaks your stuff. This script is
    										provided AS IS without warranty of any kind. I disclaim all implied warranties including, 
    										without limitation, any implied warranties of merchantability or of fitness for a particular
    										purpose. The entire risk arising out of the use or performance of the sample scripts and 
    										documentation remains with you. In no event shall I be liable for any damages whatsoever 
    										(including, without limitation, damages for loss of business profits, business interruption,
    										loss of business information, or other pecuniary loss) arising out of the use of or inability
    										to use the script or documentation. 
    Acknowledgements 	: 
  	Assumptions				: 
    Limitations				: 
    Known issues			: None yet, but I'm sure you'll find some!    										

		New-BalloonTip -icon [none|info|warning|error] -title [title text] -text [text]

		Creates a balloon tip in the lower right corner.


		This function does support pipeline input.

	#Requires -Version 2.0

	[CmdletBinding(SupportsShouldProcess = $true)]
		# Specifies the type of icon shown in the balloon tip
		[parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
		[ValidateSet("None", "Info", "Warning", "Error")]
		[string] $Icon = "Info",

		# Defines the actual text shown in the balloon tip
		[parameter(Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true, HelpMessage = "No text specified!")]
		[string] $Text,

		# Defines the title of the balloon tip
		[parameter(Position = 2, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true, HelpMessage = "No title specified!")]
		[string] $Title
	  [system.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null
	  $balloon = New-Object System.Windows.Forms.NotifyIcon
	  $path = Get-Process -id $pid | Select-Object -ExpandProperty Path
	  $balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
	  $balloon.BalloonTipIcon = $Icon
	  $balloon.BalloonTipText = $Text
	  $balloon.BalloonTipTitle = $Title
	  $balloon.Visible = $true
	  Remove-Variable balloon
	} # end PROCESS
} # end function New-BalloonTip

And you can call it by either supplying the parameter names:

New-BalloonTip -icon info -text "PowerShell script has finished processing" -title "Completed"

or not:

New-BalloonTip info "PowerShell script has finished processing" "Completed"
Categories: PowerShell Tags: ,
  1. September 28th, 2013 at 18:54 | #1

    Nice one, I love it !

  2. Pij
    November 13th, 2013 at 09:57 | #2

    running fine, but when i close the script editor, notification icon is closed too.

    How could I script to keep notification after running script ? ( creating new process ? )

    • Pat Richard
      November 13th, 2013 at 11:09 | #3

      Which editor? I only run it from scripts from PowerShell itself. I don’t use an editor.

  3. Lars Gregersen
    January 27th, 2014 at 05:34 | #4

    I think this is a nice example. However you fail to call dispose on the $balloon variable which leads to memory/resource leaks.

    • Pat Richard
      January 31st, 2014 at 02:12 | #5

      Thanks for pointing that out. I’ve updated the entire function, including calling Remove-Variable to dispose of the object.

  1. May 7th, 2014 at 16:45 | #1