Creating Balloon Tips using PowerShell


During my presentation at the Dogfood Conference in Columbus Ohio this morning, there was a lot of interest about the balloon tips that popped up during my script execution. I thought I would do a quick post to share this, as I recently saw it on my daily PowerShell.com PowerTip email and loved it enough to incorporate it into my “Build Your SharePoint Internet Presence with PowerShell” demonstration.

It’s pretty much as simple as creating a new System.Windows.Forms.NotifyIcon object and then setting some properties and calling the ShowBalloonTip() method.

Here’s my version of it, which I created as a function so I could call it like a Cmdlet:

function New-BalloonTip {
[CmdletBinding()]
Param(
$TipText='This is the body text.',
$TipTitle='This is the title.',
$TipDuration='10000'
)
[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
$icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)
$balloon.Icon = $icon
$balloon.BalloonTipIcon = 'Info'
$balloon.BalloonTipText = $TipText
$balloon.BalloonTipTitle = $TipTitle
$balloon.Visible = $true
$balloon.ShowBalloonTip($TipDuration)
}

Here’s how you run it:

New-BalloonTip -TipTitle "This is the title" -TipText "This is my custom message"

And here’s what it looks like:

Advertisements

2 thoughts on “Creating Balloon Tips using PowerShell

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s