A sample implementation of windows balloon notification for powershell is as follows:
Add-Type -AssemblyName System.Windows.Forms function FnShowBalloon { [CmdLetBinding()] param($title, $message, [string] $icon = 'info', [int] $delay = 20000, [int] $sleep=0) Switch($icon.ToString().ToLower()) { 'warn' {$iconInstance = [System.Windows.Forms.ToolTipIcon]::Warning} 'error' {$iconInstance = [System.Windows.Forms.ToolTipIcon]::Error} 'info' {$iconInstance = [System.Windows.Forms.ToolTipIcon]::Info} default {$iconInstance = [System.Windows.Forms.ToolTipIcon]::None} } $notification = New-Object System.Windows.Forms.NotifyIcon $path = (Get-Process -id $pid).Path $notification.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) $notification.BalloonTipIcon = $iconInstance $notification.BalloonTipTitle = $title $notification.BalloonTipText = $message $notification.Visible = $true $notification.ShowBalloonTip($delay) if ($sleep -gt 0) { Start-Sleep -s $sleep $notification.Dispose() } }
The FnShowBalloon function can be used as follows:
FnShowBalloon -title "Hello World" -message "This is a sample message" -icon info
Leave a Reply