{"id":1251,"date":"2020-08-17T16:14:32","date_gmt":"2020-08-17T04:14:32","guid":{"rendered":"https:\/\/www.ronella.xyz\/?p=1251"},"modified":"2020-08-17T16:40:28","modified_gmt":"2020-08-17T04:40:28","slug":"sample-show-balloon-notification-for-powershell","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=1251","title":{"rendered":"Sample Show Balloon Notification for PowerShell"},"content":{"rendered":"<p>A sample implementation of <strong>windows balloon notification<\/strong> for powershell is as follows:<\/p>\n<pre style=\"white-space: pre;\">Add-Type -AssemblyName System.Windows.Forms\r\n\r\nfunction FnShowBalloon {\r\n\r\n    [CmdLetBinding()]\r\n    param($title, \r\n           $message, \r\n           [string] $icon = 'info', \r\n           [int] $delay = 20000, \r\n           [int] $sleep=0)\r\n\r\n    Switch($icon.ToString().ToLower()) {\r\n        'warn' {$iconInstance = [System.Windows.Forms.ToolTipIcon]::Warning}\r\n        'error' {$iconInstance = [System.Windows.Forms.ToolTipIcon]::Error}\r\n        'info' {$iconInstance = [System.Windows.Forms.ToolTipIcon]::Info}\r\n        default {$iconInstance = [System.Windows.Forms.ToolTipIcon]::None}\r\n    }\r\n\r\n    $notification = New-Object System.Windows.Forms.NotifyIcon\r\n    $path = (Get-Process -id $pid).Path\r\n    $notification.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path)\r\n    $notification.BalloonTipIcon = $iconInstance\r\n    $notification.BalloonTipTitle = $title\r\n    $notification.BalloonTipText = $message\r\n    $notification.Visible = $true\r\n    $notification.ShowBalloonTip($delay)\r\n\r\n    if ($sleep -gt 0) {\r\n        Start-Sleep -s $sleep\r\n        $notification.Dispose()\r\n    }\r\n}\r\n<\/pre>\n<p>The <strong>FnShowBalloon\u00a0<\/strong> function can be used as follows:<\/p>\n<pre style=\"white-space: pre;\">FnShowBalloon -title \"Hello World\" -message \"This is a sample message\" -icon info\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>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 = &#8216;info&#8217;, [int] $delay = 20000, [int] $sleep=0) Switch($icon.ToString().ToLower()) { &#8216;warn&#8217; {$iconInstance = [System.Windows.Forms.ToolTipIcon]::Warning} &#8216;error&#8217; {$iconInstance = [System.Windows.Forms.ToolTipIcon]::Error} &#8216;info&#8217; {$iconInstance = [System.Windows.Forms.ToolTipIcon]::Info} default {$iconInstance = [System.Windows.Forms.ToolTipIcon]::None} } $notification = New-Object System.Windows.Forms.NotifyIcon $path [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1251"}],"collection":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1251"}],"version-history":[{"count":10,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1251\/revisions"}],"predecessor-version":[{"id":1261,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1251\/revisions\/1261"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}