THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Buck Woody

Carpe Datum!

PowerShell – Show a Notification Balloon

In my presentations for PowerShell I sometimes want to start a process (like a backup) that will take some time. I normally pop up a notification “balloon” at the start, and then do the bulk of the work, and then pop up a balloon at the end to let me know it’s done. You can actually try out this little sample (on a test system, of course) without any other code to see what it does. Then just put the other PowerShell commands in the #Do Some Work part. Oh – throw an icon (.ico file) in a c:\temp directory or point that somewhere else.

(No, this probably isn’t original. Can’t remember where I saw the original code, but I’ve modified it a bit anyway, so if you’re the original author and this looks slightly familiar, post a comment.)

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$objBalloon = New-Object System.Windows.Forms.NotifyIcon
$objBalloon.Icon = "C:\temp\Folder.ico"

# You can use the value Info, Warning, Error
$objBalloon.BalloonTipIcon = "Info"

# Put what you want to say here for the Start of the process
$objBalloon.BalloonTipTitle = "Begin Title"
$objBalloon.BalloonTipText = "Begin Message"
$objBalloon.Visible = $True
$objBalloon.ShowBalloonTip(10000)

# Do some work

# Put what you want to say here for the completion of the process
$objBalloon.BalloonTipTitle = "End Title"
$objBalloon.BalloonTipText = "End Message"
$objBalloon.Visible = $True
$objBalloon.ShowBalloonTip(10000)

Script Disclaimer, for people who need to be told this sort of thing:

Never trust any script, including those that you find here, until you understand exactly what it does and how it will act on your systems. Always check the script on a test system or Virtual Machine, not a production system. Yes, there are always multiple ways to do things, and this script may not work in every situation, for everything. It’s just a script, people. All scripts on this site are performed by a professional stunt driver on a closed course. Your mileage may vary. Void where prohibited. Offer good for a limited time only. Keep out of reach of small children. Do not operate heavy machinery while using this script. If you experience blurry vision, indigestion or diarrhea during the operation of this script, see a physician immediately.

Published Tuesday, March 23, 2010 6:26 AM by BuckWoody

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Robert Robelo said:

Hi Buck,

I recently wrote a few entries about PowerShell v2's Event Notification capabilities.

In them I use the balloon tip to display relevant information, to facilitate the balloon tip notification I wrote a Show-BalloonTip function you might want to try.

This is the entry:

<a href="http://robertrobelo.spaces.live.com/blog/cns!1D7FE2F4A61D31E1!294.entry">Balloon tip notfications</a>

This entry uses the Show-BalloonTip and Out-Speech functions to inform the user about various Background Jobs' State:

<a href="http://robertrobelo.spaces.live.com/blog/cns!1D7FE2F4A61D31E1!305.entry">How to know – and react – when a Job is done</a>

March 23, 2010 1:32 PM

Leave a Comment

(required) 
(required) 
Submit

About BuckWoody

http://buckwoody.com/BResume.html

This Blog

Syndication

Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement