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

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

Description

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  {
<#
.SYNOPSIS
  Displays a balloon tip in the lower right corner of the screen.

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

.NOTES
  Version                 : 1.3
  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 Required     : No
  Lync/Skype4B Version    : N/A
  Author/Copyright        : © Pat Richard, Skype for Business MVP - All Rights Reserved
  Email/Blog/Twitter      : pat@innervation.com   https://www.ucunleashed.com @patrichard
  Dedicated Post          : https://www.ucunleashed.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             : ExecutionPolicy of AllSigned (recommended), RemoteSigned or Unrestricted (not recommended)
  Limitations             : 
  Known issues            : None yet, but I'm sure you'll find some!                        

.LINK
  
Function: New-BalloonTip – PowerShell Function to Show Balloon Tips
.EXAMPLE New-BalloonTip -icon [none|info|warning|error] -title [title text] -text [text] Description ----------- Creates a balloon tip in the lower right corner. .INPUTS This function does support pipeline input. #> #Requires -Version 2.0 [CmdletBinding(SupportsShouldProcess = $true)] param( # Specifies the type of icon shown in the balloon tip [parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [ValidateSet("None", "Info", "Warning", "Error")] [ValidateNotNullOrEmpty()] [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!")] [ValidateNotNullOrEmpty()] [string] $Text, # Defines the title of the balloon tip [parameter(Position = 2, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true, HelpMessage = "No title specified!")] [ValidateNotNullOrEmpty()] [string] $Title, # Specifies how long to display the balloon tip [parameter(Position = 3, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)] [ValidateNotNullOrEmpty()] [ValidatePattern("[0-9]")] [int] $Timeout = 10000 ) PROCESS{ [system.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null # Add-Type -AssemblyName System.Windows.Forms #if (! $script:balloon) { #$script:balloon = New-Object System.Windows.Forms.NotifyIcon $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 $balloon.ShowBalloonTip($Timeout) $balloon.Dispose() } # 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'

Donations

I’ve never been one to really solicit donations for my work. My offerings are created because *I* need to solve a problem, and once I do, it makes sense to offer the results of my work to the public. I mean, let’s face it: I can’t be the only one with that particular issue, right? Quite often, to my surprise, I’m asked why I don’t have a “donate” button so people can donate a few bucks. I’ve never really put much thought into it. But those inquiries are coming more often now, so I’m yielding to them. If you’d like to donate, you can send a few bucks via PayPal at https://www.paypal.me/PatRichard. Money collected from that will go to the costs of my website (hosting and domain names), as well as to my home lab.

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