Function: New-BalloonTip – PowerShell Function to Show Balloon Tips
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:
These are the same type of balloon tips that alert us to outdated or disabled security settings, pending updates, etc.
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.0
Rights Required : Local admin on server
: ExecutionPolicy of RemoteSigned or Unrestricted
Author(s) : Pat Richard (pat@innervation.com)
Dedicated Post : http://www.ehloworld.com/1038
Disclaimer : You running this script means you won't blame me if this breaks your stuff.
.EXAMPLE
New-BalloonTip -icon [none|info|warning|error] -title [title text] -text [text]
Description
-----------
Creates a balloon tip in the lower right corner.
.LINK
http://www.ehloworld.com/1038
.INPUTS
None. You cannot pipe objects to this script.
#Requires -Version 2.0
#>
[CmdletBinding(SupportsShouldProcess = $true)]
param(
[parameter(Position = 0, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $false, HelpMessage = "No icon specified. Options are None, Info, Warning, and Error!")]
[ValidateSet("None", "Info", "Warning", "Error")]
[string]$Icon = "error",
[parameter(Position = 1, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, Mandatory = $true, HelpMessage = "No text specified!")]
[string]$Text,
[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
$balloon.ShowBalloonTip(10000)
} # 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
Function, PowerShell





Follow Me