Home PowerCLI Get Notifications During Long-Running PowerShell Scripts

Get Notifications During Long-Running PowerShell Scripts

by Brian

You’ve been there. Running a long PowerShell script that you know will take more than a few seconds (maybe minutes or even hours). Either you are running the script and leaving it up on a second monitor, or you are periodically alt-tab’ing back to it to see it’s progress. Either way, I’ve started using the Windows notifications to inform me of progress with my scripts and I have to say, I really like it. I decided as I was using it this weekend that I would finally throw it into a function and post it on Github. I do not recall where I originally found this ability, but I have since taken it and modified it for my needs.


What does it do?

Set-TaskbarNotification allows users to create popup notifications in the bottom-right of their screen from PowerShell. In the images below, I have the command I ran and the notification popup that corresponded to each command. As you can see, this is very simple and straightforward and can allow users to continue on with their day-to-day tasks, while still receiving updates from scripts they are running.

How does it work?

This script taps into the ‘System.Windows.Forms.NotifyIcon’ object. In this function, I’ve created a number of checks that makes using it so easy that the only required field is the actual message itself.

  • If you do not add a title, it will automatically take the title of the PowerShell session window that it is running from (default will be ‘Windows PowerShell’ unless you run scripts to change the titles of your PS sessions)
  • It sets a default notification timeout of 5 seconds. This can be changed with the -TimeoutMS parameter
  • It sets the default balloon icon to ‘info’ although you can specify “None”,“Info”,“Warning”,“Error” with the -BalloonIcon parameter
  • It sets the default taskbar icon to the PowerShell icon, but you can change that as well.

Where can I get it?

You can find it on my github page, here https://github.com/vtagion/Scripts/blob/master/Set-TaskbarNotification.ps1


Try it out and drop me a comment on here or twitter if you found it useful!


You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More