<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Notifications | KC's Blog</title>
	<atom:link href="https://www.kjctech.net/tag/notifications/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.kjctech.net</link>
	<description></description>
	<lastBuildDate>Tue, 24 Jan 2023 18:20:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i0.wp.com/www.kjctech.net/wp-content/uploads/2016/12/cropped-KC-Logo.png?fit=32%2C32&#038;ssl=1</url>
	<title>Notifications | KC's Blog</title>
	<link>https://www.kjctech.net</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">24634607</site>	<item>
		<title>4 Types of Notifications Generated in PowerShell</title>
		<link>https://www.kjctech.net/4-types-of-notifications-generated-in-powershell/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=4-types-of-notifications-generated-in-powershell</link>
					<comments>https://www.kjctech.net/4-types-of-notifications-generated-in-powershell/#comments</comments>
		
		<dc:creator><![CDATA[Kent Chen]]></dc:creator>
		<pubDate>Fri, 15 Jun 2018 23:58:33 +0000</pubDate>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Notifications]]></category>
		<category><![CDATA[powershell]]></category>
		<guid isPermaLink="false">https://www.kjctech.net/?p=3949</guid>

					<description><![CDATA[<p>When a PowerShell script takes long time to finish, it&#8217;s nice to have some sort of notification set up in place to notify you when the job is finished. Here are three type of notifications you can create in PowerShell. Notify via Email PowerShell has a native cmdlet Send-MailMessage that can be easily set up and use. I have written [&#8230;]</p>
The post <a href="https://www.kjctech.net/4-types-of-notifications-generated-in-powershell/">4 Types of Notifications Generated in PowerShell</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>When a PowerShell script takes long time to finish, it&#8217;s nice to have some sort of notification set up in place to notify you when the job is finished.</p>



<p>Here are three type of notifications you can create in PowerShell.</p>



<h2 class="wp-block-heading">Notify via Email</h2>



<p>PowerShell has a native cmdlet Send-MailMessage that can be easily set up and use. I have written <a href="https://www.kjctech.net/setting-up-a-scheduled-batch-job-that-notifies-me-in-email-when-finished/" target="_blank" rel="noopener">this post</a> early this year that covers the basics of it with an example.</p>



<h2 class="wp-block-heading">Notify via a beep</h2>



<p>Adding the following line at the end of your script and it will make a beep when the job is finished.</p>



<pre class="wp-block-preformatted">[console]::beep(2000, 1000)</pre>



<p>You will need two numbers for the beep to work. The first number controls the pitch of the tone while the second number controls the duration. You can adjust these numbers to suit your own cases.</p>



<h2 class="wp-block-heading">Notify via a message box</h2>



<p>There are a number of ways that you can use to pop up a message box in PowerShell. Here is one that uses the script host object that looks fairly easy to use and engage. Thanks to <a href="http://meritum.cloud/blog/powershell-script-notify-you-when-server-finished-rebooting/" target="_blank" rel="noopener">Shaun Ritchie</a>.</p>



<pre class="wp-block-preformatted">$wshell = New-Object -ComObject Wscript.Shell <br/>$Output = $wshell.Popup("The task has finished")</pre>



<figure class="wp-block-image"><img data-recalc-dims="1" fetchpriority="high" decoding="async" width="353" height="215" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/06/PowerShell-dialog-box.png?resize=353%2C215&#038;ssl=1" alt="" class="wp-image-3998" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/06/PowerShell-dialog-box.png?w=353&amp;ssl=1 353w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/06/PowerShell-dialog-box.png?resize=250%2C152&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/06/PowerShell-dialog-box.png?resize=100%2C61&amp;ssl=1 100w" sizes="(max-width: 353px) 100vw, 353px" /></figure>



<p>You can explorer more properties of the Popup box to stylize the message box.</p>



<h2 class="wp-block-heading">Notify by balloon tip / toast notification</h2>



<p>The balloon tips comes to us since Windows 7 and can also be programmed in PowerShell. This is probably the most fun way to deliver a notification among other types we just covered.</p>



<p>You can follow this awesome <a href="https://mcpmag.com/articles/2017/09/07/creating-a-balloon-tip-notification-using-powershell.aspx">how-to write up</a> by Boe Prox on MCP Mag to generate one balloon tip for your own.</p>



<p>For starters, here is the code:</p>



<pre class="wp-block-preformatted">Add-Type -AssemblyName System.Windows.Forms <br/>$global:balloon = New-Object System.Windows.Forms.NotifyIcon<br/>$path = (Get-Process -id $pid).Path<br/>$balloon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($path) <br/>$balloon.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning <br/>$balloon.BalloonTipText = 'What do you think of this balloon tip?'<br/>$balloon.BalloonTipTitle = "Attention $Env:USERNAME" <br/>$balloon.Visible = $true <br/>$balloon.ShowBalloonTip(5000)<br/></pre>



<p>That generates the following balloon tip popup that lasts for 5 seconds.</p>



<figure class="wp-block-image"><img data-recalc-dims="1" decoding="async" width="465" height="211" src="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/06/PowerShell-balloon-tip.png?resize=465%2C211&#038;ssl=1" alt="" class="wp-image-4028" srcset="https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/06/PowerShell-balloon-tip.png?w=465&amp;ssl=1 465w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/06/PowerShell-balloon-tip.png?resize=250%2C113&amp;ssl=1 250w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/06/PowerShell-balloon-tip.png?resize=450%2C204&amp;ssl=1 450w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/06/PowerShell-balloon-tip.png?resize=360%2C163&amp;ssl=1 360w, https://i0.wp.com/www.kjctech.net/wp-content/uploads/2018/06/PowerShell-balloon-tip.png?resize=100%2C45&amp;ssl=1 100w" sizes="(max-width: 465px) 100vw, 465px" /></figure>



<p>Even better, there is an open source PowerShell
	<g class="gr_ gr_3 gr-alert sel gr_spell gr_replaced gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" id="3" data-gr-id="3">module</g> called <a href="https://github.com/Windos/BurntToast" target="_blank" rel="noopener">BurntToast</a> that you can use to generate balloon tips with a lot more options.</p>The post <a href="https://www.kjctech.net/4-types-of-notifications-generated-in-powershell/">4 Types of Notifications Generated in PowerShell</a> first appeared on <a href="https://www.kjctech.net">KC's Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://www.kjctech.net/4-types-of-notifications-generated-in-powershell/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3949</post-id>	</item>
	</channel>
</rss>
