Skip to content
CBT Nuggets
DemoBook a Demo

Send Windows Notifications with PowerShell

This skill teaches you how to use PowerShell and the BurntToast module to send custom operating system notifications on Windows 10. It covers configuring context menus, progress bars, custom images, sounds, and buttons for notifications. The skill is designed for IT professionals and system administrators who are familiar with PowerShell basics and want to enhance their automation scripts with advanced notification features.

Full skill from PowerShell Automation. Preview the IT training 23,000+ organizations trust.

1h 8m

Skill 5 of 16 in PowerShell Automation

Overview

Join Trevor Sullivan as he teaches you how to send operating system notifications to Windows 10 by using PowerShell and the BurntToast module.

Learn how to configure context menus and progress bars on Windows 10 toast notifications. Gain the skills you need to send custom notifications with custom images, sounds, and buttons.

Introduction to Windows Notifications

In this skill, we'll be exploring how to use PowerShell, with the BurntToast module, to send operating system notifications to Windows 10.

Installing and Exploring the BurntToast Module

Let's explore the BurntToast open source module on GitHub, and PowerShell Gallery, and then install and explore its capabilities.

Knowledge Check

Which PowerShell command should you use to search for a module in the PowerShell Gallery?

Creating Your First BurntToast Notification

Now that we've explored the BurntToast module's capabilities, let's start sending custom notifications!

Knowledge Check

Which parameter on the Get-Help PowerShell command is used to retrieve the entire help text for another command?

Customizing Notifications with a Title, Image, and Sound

Let's take a look at how to add a more prominent title to Windows 10 notifications, as well as customize the image that appears on the notification, and the corresponding sound that's played.

Knowledge Check

You can download any sound file and use it for BurntToast notifications. True or false?

Want to answer questions like this yourself?
with no purchase required. Already have an account?

Enabling Snoozing and Adding Custom Buttons on Notifications

You can add custom buttons with specific actions directly onto Windows 10 toast notifications, using the BurntToast module.

Knowledge Check

To create a new BurntToast Button object, which PowerShell command should you use?

Adding Context Menus to Notifications

You can configure context menus on Windows 10 toast notifications, that expose actions to perform as a result of the notification.

Knowledge Check

Each Windows 10 notification can only have one context menu item. True or false?

Want to answer questions like this yourself?
with no purchase required. Already have an account?

Building Progress Bars with Windows Notifications

You can configure progress bars on Windows 10 toast notifications, using the BurntToast module. Let's check out how!

Knowledge Check

Which parameter on the New-BurntToastNotification command will avoid receiving duplicate notifications in the Windows 10 Action Center?

Review and Call to Action

Conclusion

I hope this has been informative for you and I would like to thank you for consuming.

View Transcript

Introduction to Windows Notifications

0:04Hi, guys.

0:05My name is Trevor Sullivan.

0:06Welcome to this CBT Nuggets skill

0:08where we're going to be talking about a really

0:10exciting topic surrounding the PowerShell automation

0:14framework.

0:15Now, this particular skill is going

0:17to specifically cover using PowerShell on the Microsoft

0:21Windows platform.

0:23And the task that we're going to be performing using PowerShell

0:26in this skill is going to be sending operating system

0:30notifications from your PowerShell automation scripts.

0:34Now, why might you want to send notifications

0:36from your automation scripts?

0:38Well, there's a lot of different use cases

0:40for sending notifications.

0:42For example, you might want to send a notification

0:45when a backup job that runs for several hours has completed.

0:50So that way, you just have a visual indication

0:52that the job is complete, and you can now go and take action

0:56on that particular job that ran.

0:58Another thing you might want to do

1:00is perform some cleanup of some kind of system.

1:03So for example, maybe you've got some file system locations that

1:06have a lot of outdated files, and you

1:08want to go back and clean up that data.

1:11Well, depending on where that data is stored

1:14and how much data you have, it could

1:16take several minutes or perhaps even hours

1:19to perform a cleanup of that data.

1:22The same thing could be true inside of a database.

1:24Maybe you want to go through and query for certain data inside

1:27of a database and go out and clean stale records out

1:30of that database to make sure that the database is optimized

1:33and performing very well.

1:35There's a whole bunch of different use cases for sending

1:37notifications, and we're just going

1:39to explore a community module called BurntToast

1:43and how to actually use all of the different functionality

1:46that is exposed by this feature rich module.

1:50If you're just getting familiar with PowerShell

1:52for the first time, this probably isn't the best skill

1:54to get started with PowerShell on because we're

1:57going to assume that you already know how to install PowerShell,

2:02and that you understand some of the basic concepts

2:04in PowerShell, like how modules work, and how commands work,

2:08and how parameters on different PowerShell functions work.

2:12So go ahead and check out some of our other training

2:14on CBT Nuggets if this is your first time touching PowerShell.

2:18I hope this has been informative for you,

2:19and I'd like to thank you for viewing.

Installing and Exploring the BurntToast Module

0:04Hi, guys, and welcome back.

0:06In this video, we're going to start

0:08by taking a look at the BurntToast PowerShell

0:10module that enables us to create notifications

0:14from our PowerShell scripts on the Microsoft Windows platform.

0:17But before we do that, let's take a really quick look

0:20at a GitHub repository that serves as a companion

0:24to this video training skill at CBT Nuggets.

0:27So if you head over in your web browser

0:29to github.com/cbttrevor, there is going to be a PowerShell

0:35notifications repository just like on my screen here.

0:39So github.com/cbttrevor will take you over to this GitHub

0:43organization.

0:44And within this GitHub organization,

0:47I've got a bunch of different companion repositories

0:50that match up with some of the training content

0:52that I've been producing on the CBT Nuggets platform.

0:55So go ahead and drill into the PowerShell notifications

0:58repository.

0:59I know it says "private" right here,

1:00but by the time that this training goes live,

1:03that will be publicly accessible to anyone.

1:06And then what you'll see here is that I've

1:08broken down each of the learning objectives

1:10for this particular skill into subfolders

1:14so that you can follow along very

1:15easily after this recording has been produced.

1:18So go ahead and just use the Git clone command

1:22to clone this repository, either using the SSH URI or the HTTPS

1:27URI.

1:28It really doesn't matter which one

1:29you use since you're just going to be

1:31cloning it locally and using it in a read only capacity.

1:35Now one of the great things about the BurntToast PowerShell

1:38module that we're going to be looking at

1:40is that it's produced by a community

1:42member named Josh King.

1:44He's the user who has produced this module,

1:46or started off this module, and has been actively maintaining

1:50it for quite some time.

1:51So Josh's GitHub user name is Windos, Win-D-O-S.

1:58I'm not really sure what that stands for.

2:00But under his user name, there is a GitHub repository

2:04called BurntToast.

2:06And as you can see here, this is where

2:07all of the active development of this PowerShell module

2:10is occurring.

2:11In fact, there's even a nice little graphic here,

2:14and there's a bunch of badges here

2:15that show you the latest version of the module that's

2:19been published to the PowerShell Gallery, which

2:21is version 0.8.2.

2:24The number of downloads, which I believe

2:26is actually incorrect at this point in time

2:28due to some statistical issues with the PowerShell Gallery.

2:31And it also shows you the CI/CD pipeline that's running inside

2:34of the Azure pipeline service, as

2:36to whether the build is succeeding or failing

2:39for some reason.

2:40We also see the code coverage here,

2:42which indicates how much of the code

2:44is being covered by tests, automated tests.

2:48Now as you'll see, we're going to basically

2:50be installing this PowerShell module using the Install Module

2:53command, which is included with PowerShell out of the box.

2:58So you don't need to install any modules to get

3:00that install module, it just comes as part of the PowerShell

3:03package.

3:03And we use that command to install other third party

3:06modules, such as BurntToast in this case,

3:09from the PowerShell Gallery at powershellgallery.com.

3:13Now, if you scroll down in the README here a little bit,

3:16you'll see some examples, or just screenshots, and example

3:19commands that you can call to send operating system

3:22notifications in the Windows 10 platform using the BurntToast

3:27module.

3:28Now, this is certainly not comprehensive.

3:30We're going to explore a lot of the intricate options that

3:33are available to you in this module that

3:36allow you to do even more customizations than just

3:38what is shown here.

3:40But as some preliminary examples,

3:41you can kind of see that there is custom text being emitted,

3:45there is a custom header or title that's

3:47being emitted onto the notification,

3:50and you can even customize the image

3:53that is being used to present the notification as well.

3:57And then down here, you can actually

3:58see that if we had maybe a meeting reminder to say, hey,

4:01you've got a meeting coming up in 10 or 15

4:03minutes or something like that, that you can actually

4:06create a snoozeable alarm notification using

4:09this module as well.

4:10So this is a lot of functionality in here

4:13and there's a lot more that's not even being presented there.

4:16But first, I want to show you the PowerShell Gallery.

4:18So this is the repository, or sometimes known as a registry,

4:22that's built on the Nugget APIs that allow you to publish

4:27and download packages.

4:29So if you were to go to powershellgallery.com

4:31in your web browser and search for the BurntToast module,

4:36you should see that show up here.

4:38And we're only getting one result

4:39because BurntToast is a pretty unique, kind of cool name.

4:42And if you're wondering where the name BurntToast actually

4:45came from, the toast part of it actually

4:48came from the Windows platform.

4:50So when you get a notification down in the lower right

4:52corner of the screen--

4:53kind of where I am in this particular video--

4:56you would actually call that a notification toast.

4:59And what's cool is that the notifications will actually

5:01show up over here in what's called the Windows 10

5:05Action Center.

5:06And if you want to open up the Action Center really

5:08easily, you can simply hit the Windows A on your keyboard,

5:14and that shortcut will actually invoke the Action Center

5:17and show you all of the notifications, along with all

5:19of these settings down here for your system.

5:24So what we're going to do now is actually jump into Microsoft

5:27Visual Studio code, which is my preferred text editor of choice

5:31any time that I'm doing any kind of development work

5:33or programming tutorials, like this one.

5:36And if you don't have Visual Studio code,

5:37I would strongly recommend you download it

5:39at code.visualstudio.com.

5:42But for now, I'm just going to jump over here.

5:44And I've already opened up this PowerShell and notifications

5:47Git repository that I've cloned locally on my system--

5:50actually, I developed it locally here.

5:52But I didn't have to clone it, of course.

5:53But basically, we're in the 02 lesson here.

5:57And our objective here is to basically get

6:00the module installed and learn about some

6:02of the core capabilities that it offers.

6:05So jump over into these script.ps1 file, which is just

6:09a simple PowerShell script.

6:10The actual name of the script could be whatever you want.

6:12So you could hit F2 over here in the Explorer

6:15and call it Install BurntToast.

6:19The name of the actual script doesn't really matter.

6:22I just happen to--

6:23script.ps1 is kind of a generic name,

6:25just so that you have something to point

6:27to in each of the different lessons here.

6:29So go ahead and pop that open.

6:31And then in BS code, I'll just take

6:32Control-B to close that sidebar there just

6:35give us a little bit more space to work with on the screen.

6:38And on the very first line here, the first two lines rather,

6:41you'll see that we are going to use a PowerShell command called

6:44Find Module that allows you to search the PowerShell

6:48gallery that we just looked at-- powershellgallery.com.

6:51And you can search for a module based on its name.

6:55You can also search based on things like tags.

6:58So I could do Find-Module -tag notifications, for example.

7:03And basically, this will allow you to search

7:05through the PowerShell Gallery.

7:07But as long as you know what the module name is--

7:10so I've actually got a bunch of different notifications

7:12related modules here.

7:14But if you already know what the module name is,

7:16it's usually just easiest to search for it

7:18by its actual name.

7:20And that will show you the latest version

7:23of that PowerShell module that is in the gallery.

7:27Now, if you have a specific scenario where

7:29you want to install an older version of a particular module,

7:32you can actually do Find-Module -AllVersions.

7:36And as long as you specify the module name along

7:39with all versions, it'll actually

7:41show you the historic versions that were previously published,

7:45so that you can install a specific version of that module

7:49based on your specific requirements, which

7:51is pretty cool.

7:53So now what we're going to do, now

7:54that we know the name of the module that we want to install,

7:57we're going to call the Install Module command.

7:59And again, this is built into PowerShell.

8:02So if we're to do Get Command install dash module,

8:07you should see that we get back the Install Module

8:10command here, and it's part of the PowerShell Get Module

8:15that's included with PowerShell.

8:16That's just part of the core PowerShell product

8:18and what we're going to do is basically

8:20specify the name parameter, which obviously

8:23is the name of the module that we

8:24want to install from the PowerShell Gallery.

8:27And then there's this scope parameter.

8:28So if you don't specify the scope parameter

8:31and you just do Install Module dash name,

8:33then that is going to install the module to your admin

8:37directory or your all users directory,

8:40so that any user who logs into the system can use that module.

8:44Now, if I tack on the scope current user,

8:46that will install to my current user profile directory

8:50instead of installing to all users,

8:52and it doesn't require administrative permissions.

8:55So like me, if you have Visual Studio code running

9:00as a nonadministrative user under user account control, UAC

9:04in Windows, then it's preferred, generally,

9:07to install to your current user directory

9:09so that you don't have to run VS Code as an administrator,

9:13and potentially open yourself up to security vulnerabilities.

9:17So now that we have installed the module here,

9:20the next thing that you probably want to do

9:22is import the module.

9:23Now importing modules is not strictly necessary

9:26in PowerShell, thanks to a feature

9:28called PowerShell module auto loading.

9:31And there's actually a variable called PS Module Auto Loading

9:35Preference that you can set if you explicitly

9:38want to disable module auto loading,

9:40but it is actually enabled by default.

9:42So it's a good practice to call Import Module,

9:45just so that you can specify where inside of your script

9:50you want to import a module.

9:51Maybe you want to do it at the beginning,

9:53maybe you want to do it somewhere partway

9:54through your script once you actually

9:56need the functionality that's exposed

9:58by that particular module.

9:59But just be aware that in some cases,

10:01you might need to explicitly import it.

10:04Now, once the module has been imported into our environment,

10:08we can run GMO, which is short for Get dash Module.

10:12Sorry.

10:13Let me type that correctly there.

10:14So Get dash Module.

10:16And if you scroll through the list of modules,

10:18you should see BurntToast imported

10:20into your current PowerShell session.

10:23So now the next thing that we typically do with a PowerShell

10:25module when we're new and we're just learning about the module,

10:28and we're kind of trying to figure out

10:30how to actually use it--

10:31I mean, you could read the documentation for it.

10:33Documentation isn't always up to date,

10:35so sometimes it's just nice to have introspection mans that

10:38allow us to inspect the module and see what is available.

10:42So if we run Get Command Module BurntToast,

10:46it'll actually spit out a list of all

10:48the different PowerShell commands that are exported

10:52by the BurntToast module.

10:54So this is really convenient.

10:56So you can see there's a whole bunch of different commands

10:58here that allow us to create these things, like headers,

11:00images, inputs, progress bars, text, visual elements,

11:05and things like that.

11:06It might seem a little bit overwhelming at first,

11:08but by the end of this skill, you'll

11:10understand how to use many of these commands in more detail.

11:14However, I'm going to draw your attention specifically

11:17to this one command called New BurntToast Notification.

11:20As well as a second one called, Submit BT Notification.

11:23These are really going to be the meat of where

11:27presenting a notification to the end user

11:29is going to come into play.

11:32So now that you understand how to learn about the module,

11:35get it installed, and inspect with the commands that

11:38are exported by that module, let's go ahead

11:40and actually build your first notification using this module.

11:44I hope this has been informative for you

11:46and I'd like to thank you for viewing.

Creating Your First BurntToast Notification

0:04Hi, learners.

0:05Welcome back.

0:06In this video, we're going to take a look

0:08at how to create your first notifications using

0:11the BurntToast PowerShell module that is being developed

0:15by a community member.

0:17Now, in the previous video, we took a look

0:18at how to get the module installed

0:20and to take a look at how to introspect the module

0:23or examine the module to see what commands are exported

0:27by it.

0:27So now, let's jump back into a Visual Studio Code

0:30and take a look at how to actually invoke

0:33the new BurntToast notification command.

0:37I'm just going to switch back over to my desktop here.

0:40And I've got Visual Studio code open in front of me

0:42just as I did in the previous video.

0:44And the first thing I'd like to call your attention to is that

0:47if you're following along with the companion GitHub

0:50repository, go ahead and just jump over into the 03

0:53directory.

0:54And our objective here is really just

0:56to focus on learning about the basics of creating

0:59notifications.

1:01So open up the script dot ps 1 file

1:03and hit Control-B just to close the sidebar.

1:05That'll give us a little extra room to work with on the screen

1:08here.

1:08Now, the first thing that you typically

1:10do once you've got a module installed

1:12and you know what command do you want to invoke

1:14is you can call the Get-Help command.

1:17And that's going to print out some useful information

1:20about the command.

1:22But if we do Get-Help dash name New-BurntToast notification,

1:27it'll give us a brief synopsis of what

1:29this particular command does.

1:31And then under syntax here, it's going

1:34to show us how to actually invoke the command.

1:38And basically show us all of the supported parameters

1:41and what kinds of values to pass into each of those parameters.

1:46Now, a lot of PowerShell commands out

1:47there are pretty simplistic in nature

1:49and don't offer a whole ton of parameters.

1:52But New-BurntToast notification is not one of those.

1:56It actually is very customizable.

1:58And it has lots of different parameters on it

2:00that can be called in different configurations.

2:04So you might see a lot of redundancy.

2:05So as you're looking at the syntax, you're like,

2:07man now I've got New-BurntToast notification dash text.

2:11And then I've got New-BurntToast notification dash text again,

2:14and again, and again, et cetera.

2:17So why are we seeing this duplication here?

2:19Well, PowerShell has a concept called parameter sets.

2:24And basically, when you're building out

2:25a PowerShell function like newsprint BurntToast

2:28notification, that's a PowerShell function.

2:30When you specify the input parameters

2:33through that function, you can actually

2:35assign them to different what are called parameter sets.

2:39And so what that allows you to do

2:40is actually call the same command or the same function,

2:43in this case, we're going to call

2:45New-BurntToast notification.

2:47But there are different groups of parameters

2:49that work together somewhat differently to get a desired

2:54result. So if you start looking through the list here,

2:56you actually start to see some variation in the parameters

3:00that are being offered here.

3:01So for example, there is a parameter here called

3:04snooze and dismiss which we'll look at later.

3:07But if we specify that parameter,

3:09it is exclusive of certain other parameters that perhaps

3:13allow us to do things like Add Custom buttons

3:17or something like that.

3:18So just be aware that each of these syntax elements

3:23here is basically a unique parameter

3:25set that allows you to call the command in a unique way.

3:28Now, you don't need to worry too much about

3:30that because a lot of these commands that we're

3:32going to be calling are pretty simplistic in nature.

3:34And we're just going to be using maybe one or two parameters

3:37like dash text to customize the actual text that's being

3:41displayed on the notification.

3:42And then down here, under the description field

3:44you get a little bit more deep information than the synopsis.

3:48A synopsis is this like a one sentence overview

3:51of what the command does.

3:52And then if you really want to get a deeper understanding

3:54of the command, you can drill down under description

3:56and take a look there.

3:58Now, something else that you can do

3:59is you Get-Help dash name and then tack on the dash full.

4:05So by default, there are certain elements

4:07from the help that are being committed by the help system.

4:10But if you do dash full, then it'll

4:12actually print out a lot more information.

4:15So it actually show you the built in examples.

4:18So we can take a look at example number

4:19one which is just a very basic call

4:21to New-BurntToast notification.

4:23Then example two, gets a little bit more

4:25advanced where we tack on a custom parameter.

4:28And then it just progressively gets more and more complex.

4:33There's also some more information

4:34that is shown in here as well that gives you information

4:39about the parameters.

4:41So if you do Get-Help desk full, you'll

4:44actually get this parameter section that opens up.

4:46And it actually tells you a nice little description or what

4:50each of the parameters does.

4:52So for example, the text parameter it says,

4:54specifies the text to show on the notification.

4:57Up to three strings can be displayed.

4:59And the first will be boldened as a title.

5:03So that's very helpful information to know.

5:06So let's take Control-Tilly to close the integrated

5:09terminal in the VS code.

5:11And let's take a look at a very simple example.

5:13In fact, I'm going to duplicate this line up using

5:15Alt-Shift up arrow just to copy the line up.

5:18And then I'm going to remove the text [INAUDIBLE]..

5:20I want to show you just how easy it

5:22is to get started with this module.

5:24So on line number five here, if I just

5:25put my cursor on line number five and hit F8,

5:28F8 will tell VS code to run the current line where

5:32the cursor is located.

5:34And so that's going to just call New-BurntToast notification.

5:37If I do that again, you'll see on the bottom right

5:40of the screen here I'm getting just a default notification

5:43with a nice little default icon there.

5:45And it says Windows PowerShell.

5:49Now, obviously, notifications are really only meaningful

5:52if they have custom text associated with them.

5:55So as we just looked at we can specify the text parameter

5:59and that will specify the text to display.

6:01So let's hit F8 here on line number six now.

6:04And you'll see that we have now customized the text

6:07to say my first notification.

6:09And it still has the default image.

6:11And it's telling us it's from Windows PowerShell.

6:15Now, what if you wanted to specify some dynamic content

6:18for the text?

6:19Like maybe you want to display how many unread emails you

6:22currently have.

6:23Or how many computer accounts are in Active Directory that

6:27are older than 90 days.

6:28Or something useful, some systems management information.

6:32Well, what I can do here in this example is actually wrap

6:35the text in parentheses and use this concept called .NET string

6:40formatting or substitution where I can basically [INAUDIBLE]

6:44Get-Process dot count.

6:46And if I hit F8 there, you'll see it just prints out

6:48a number which is useful.

6:50That's telling me how many processes are

6:52running on the current system.

6:54And then I can specify my string on the left hand

6:57side of this dash F operator which is short for string

7:00formatting in PowerShell.

7:02And right here, you'll see this curly brace

7:05with a zero in the middle.

7:06And that's basically the first element in an index--

7:10an array of elements on the right hand side of the dash F

7:13operator that we want to substitute in there.

7:16So it's a zero based index because it's an array.

7:18And so basically, this first element here Get-Process

7:20dot count is going to get substituted where

7:23this zero is in the string.

7:25So this is just a nice way of constructing a string

7:28without having to use a string concatenation where you say

7:31here's the first part of my string,

7:33plus this dynamic value, plus some other static value.

7:37Just a different way of expressing strings

7:39as templates.

7:41And then once we wrap all of that in parentheses,

7:43we can pass that resulting string into the text parameter

7:47and display that as a notification.

7:49So you can see I get a nice notification

7:51saying there are currently 323 processes running

7:54on the system.

7:57So now, we've added some dynamism into our message

8:00that we're posting to the notification.

8:03Now, another nice feature that the BurntToast module offers

8:08is the ability to suppress the pop up notification.

8:11And this is nice because as we explored earlier

8:14when I hit Windows-A, over here on the right hand

8:17side of the screen in the Action Center

8:20is where I have a running history of all

8:23my notifications.

8:25And maybe if you're a heavy user of the Action Center,

8:28maybe instead of popping up that notification on the screen,

8:31you actually just want to send it directly into the Action

8:35Center without displaying it.

8:37So you can do that by using what's

8:40called a switch parameter.

8:41And a switch parameter in PowerShell just really quickly

8:43basically means that if the parameter is present,

8:47then it's true.

8:48If it's not present, then it's false.

8:50So you don't actually have to pass

8:51in a true or false Boolean value into the parameter.

8:54Because the fact that this parameter is specified just

8:57like this with a dash of pop up, that

9:00means that it's going to be true.

9:03Now, if you did want to force it to be true or false,

9:05you could actually put a colon and then

9:06put either true or false.

9:08But that's a little bit less common.

9:10So I'm just going to specify some static text here and say,

9:14I'm in the action centre.

9:15And we're going to add on that suppress pop up parameter.

9:19If I hit F8 on that, nothing really happens.

9:22And that's because we're not popping up

9:24that notification in the lower right hand

9:26corner of the screen.

9:28Apologies that my face is kind of covering

9:30these notifications actually.

9:31I just realized that.

9:32But if I hit Windows-A, and I'll just

9:35hit Windows-Plus to open up the magnifier here,

9:38you can see that I got this message here saying,

9:41I'm in the Action Center.

9:42Even though it never popped up in the lower right hand

9:45corner of [INAUDIBLE].

9:47Let me hit Windows-Escape and that will

9:49remove my magnification there.

9:51And then one last feature that I wanted to cover in this video

9:54is the ability to specify a custom timestamp.

9:57This is really cool because if you wanted a notification

10:00to have a future timestamp or a timestamp sometime in the past,

10:06then you can actually do that by customizing

10:09the timestamp that's associated with the notification when

10:12you send it using the new BurntToast [INAUDIBLE]..

10:16So what you basically want to do is specify a date time value

10:20to this.

10:21If I hit Control-Space to invoke the intelligence here in VS

10:24code, you can see that the custom timestamp takes a date

10:27time object which is a pretty standard .NET object system dot

10:32date time.

10:33And the way that we can get a date time object in PowerShell

10:35is simply to call the Get-Date command.

10:38If I was just to select this little Get-Date command

10:41and hit F8, you'll see that it prints out this date and time.

10:45And this is actually a date time object.

10:47It's actually not just a string.

10:48It's actually an object that's being

10:51emitted as a string or a formatted as a in the terminal

10:55here.

10:55But it is actually giving us a system dot date time object.

10:59And what's cool about the system dot

11:00date time object is that if you put a period after it

11:03in parentheses here, there are actually

11:07a bunch of methods, functions that you

11:09can call on that instance of the date time object.

11:13And some of those functions that you can call,

11:18methods call are actually called add days, add hours, add

11:21milliseconds, add minutes, et cetera.

11:23If I say I want to create a notification that happened

11:2710 minutes ago or 10 minutes in the future,

11:29I can add 10 minutes.

11:31Or if you want to subtract minutes,

11:33then you can just say add negative 10 minutes.

11:36And that will actually-- they take the current date

11:39and time back to 10 minutes and do

11:41that as the custom timestamp.

11:44So let's go ahead and hit F8 on line number 15 here.

11:47You'll see I get this message pop up down here.

11:49It says, hello, I am from the past.

11:51Now, the notification itself--

11:54actually, let me just move out of the way really quickly here.

11:59There we go.

12:00So if I rerun that, you'll see that this notification doesn't

12:02actually have the date and time on it.

12:04However, if I was to open up the Action Center using Windows-A,

12:10then you'll see that we can open up the notification list.

12:15And down here below all of the more recent notifications,

12:19we have these notifications saying,

12:20hello, I am from the past.

12:22So the nice thing is that the Action Center

12:24here in the Windows platform is actually chronologically

12:28ordering those notifications even though they

12:31were sent after others.

12:33Because the timestamp is in the past so

12:35it's putting them down here in the bottom.

12:38So as you can see, there's a lot of really great functionality.

12:40Even just the basic functionality

12:42in the BurntToast module for PowerShell is really neat.

12:46Now, that you've learned some of the basics

12:48about how to create notifications,

12:50let's take a look at some other customization

12:52options like titles and sounds.

12:54I hope this has been informative for you.

12:56And I'd like to thank you for viewing.

Customizing Notifications with a Title, Image, and Sound

0:04Hi, guys, and welcome back.

0:06Now that you've learned how to get the BurntToast

0:09module installed on your system and you've explored the module

0:13and understood some of the different commands that

0:15are available in it and you've created

0:17your first notifications using this module,

0:20let's take a look at a couple of additional features

0:23that are available.

0:24Specifically, you can customize the image file

0:27that is being presented in your notification.

0:29Additionally, second of all, you can customize the heading

0:33on the notification.

0:35And then third of all, you can actually

0:37configure a custom alarm sound instead

0:39of using the default notification

0:42sound in the Windows platform.

0:44Let's jump back into Visual Studio code

0:46and take a look at how to consume

0:47these additional features.

0:50Here we are back in Visual Studio code.

0:52And if you're following along with the companion git

0:55repository, go ahead and drill into the 04 directory called

0:59Customize Notifications with a Title and Image

1:03and [AUDIO OUT].

1:05And our learning objective here is, of course,

1:07to customize the title and the image of our notifications

1:11as well as using a semi-custom sound.

1:15You can actually import your own custom sounds from the file

1:18system, but the module actually exposes several different alarm

1:21sounds that you use.

1:23So let's drill into the scripts.ps1,

1:25and I'll hit Control-B to close that sidebar.

1:28Open up our screen a little bit more here.

1:30And as we explored in the previous video,

1:33there is a parameter on the new BurntToast notification command

1:38that allows us to specify a heading.

1:40If you recall, if I hit Control-Space on the text

1:44parameter here, the text parameter actually accepts

1:48a string--

1:49or sorry-- an array of string.

1:51And so what we can do is specify the first string as a heading,

1:56and then the second and third strings

1:58will basically be printed out as just the main body

2:03of the notification.

2:05So let's go ahead and test this out.

2:07Let's hit F8 here on line number 2.

2:10And of course, I'm in the way again.

2:12And what you'll see here is that on this notification,

2:15we have a heading as well as subtext and third-level text.

2:18So it's actually putting a line space

2:22or a line break in the notification for us

2:25underneath of that heading.

2:27And the heading is a little bit bold there,

2:29so it stands out a little bit more.

2:31So one of the other things that I

2:32wanted to call your attention to is

2:34that there is limited support for how much text

2:37you can put into a notification.

2:39So if I create a notification here

2:42that has a heading of really long text,

2:45and then after that, I print out some text

2:47that's gibberish here.

2:49But I'm just trying to make a very, very, very long paragraph

2:52here--

2:52let's hit F8 on that line number 4.

2:55And what you'll notice is that--

2:58zoomed in here-- the text actually

3:01does get cut off here at the end.

3:03So as you're constructing your notifications,

3:05make sure that you are aware of those limitations, of how

3:08many characters you can print, and make sure

3:11that you are using concise messages for your window

3:14and Toast node.

3:17I'll hit Windows, Escape there and close my zoom-in effect

3:24there with the magnifier.

3:25And now what I wanted to show you

3:27is an additional heading feature that is available.

3:30So you can get a heading by just specifying

3:33at least two elements in the text parameters.

3:37So the first element will be used as the heading,

3:39and the second and/or third will be used as the main body text.

3:43However, there is a parameter on the new BurntToast notification

3:47command called the --header parameter.

3:51And what this allows us to do is actually specify

3:53a custom header value you pass into the notification.

3:57Now, this is going to make the notification a little bit

3:59taller, but it's actually going to show

4:01that heading that we specify above the main body

4:05of the notification.

4:07So the way that we create a header to pass into this header

4:10parameter is to actually use another command that's

4:13exposed by the BurntToast PowerShell module.

4:17And that command is called New-BTHeader.

4:20So if you were to call a NewBTHeader, hit a dash,

4:25you can see that you can specify a title, arguments

4:28and activation type, which we're not

4:29going to talk about right now.

4:31And you can also specify an E, which

4:33is just equally identify that header

4:36in that particular notification post.

4:38I'm honestly not sure why that's a necessary parameter.

4:41Typically, you're only going to have one header anyway.

4:44But maybe somebody can explain that to me.

4:47All right.

4:48So what we're going to do is assign

4:49the result of this command.

4:50Let's actually just select this command and hit F8.

4:53And you'll see it prints out this object

4:54to the terminal here.

4:56So what we want to do is actually capture

4:58that header object into a variable.

5:01And you can name the variable whatever you want to.

5:03I just happen to name header here

5:04because it's self-explanatory as to what

5:07that particular variable does.

5:10So once you've defined that, then you

5:12can call the New-BurntToast notification command,

5:15pass in the header parameter, and then pass in the header

5:18variable as input to the header parameter,

5:21and that will customize your [AUDIO OUT] better, of course.

5:27So let's hit F8 there, and I'll just do [AUDIO OUT] here,

5:31Windows Magnifier.

5:33And what you'll see is that we now have this notification here

5:36that has-- below, this has a custom title.

5:39And up here, above the image, we have this additional heading

5:46that's showing up up here.

5:47So this notification is going to be a little bit taller

5:49than the other ones that we were looking at before,

5:51but it has this nice heading that's separate.

5:54It's a little bit more prominent than just the

5:56heading that's shown as a default

5:58part of the notification.

6:00Now, one of the other features I wanted to cover in this video

6:03was how to customize the image that is displayed

6:06in a Notification Toast.

6:08So what we can do is pass in our header here, our text.

6:12And we can also specify another new parameter.

6:15We're going to introduce the App Logo parameter.

6:18So the App Logo parameter-- if I hit Control-Space in my editor

6:21here, you'll see that it accepts a string value-- just

6:25a singleton string, not an array of strings.

6:28Of course, because we only have one position on the screen,

6:31on the notification to display an image,

6:33we can't specify more than one, of course.

6:35Now, I've downloaded a PNG version, just

6:38a raster image version of the Python logo locally.

6:42And so we're going to basically pass that file system

6:45path in to the app logo parameter,

6:48and that will cause the Notification Toast

6:51to use that image instead of the default BurntToast image

6:55that's included with the module.

6:57So let's go ahead and hit F8 here on line number 11.

7:00And you can see that I'm now getting

7:02this nice little message here that says Message from Python.

7:06And of course, I've got my custom heading up here as well.

7:09And of course, primarily what we're interested in here

7:11is that the Python logo is now showing up

7:14as the notification image.

7:17So you could use this for other purposes,

7:19like maybe sending out notifications

7:22about how many emails are currently unread in your inbox,

7:26or if you could have a little computer icon if you're

7:28managing computer accounts in Active

7:30Directory with PowerShell, and send notifications that way

7:35as well.

7:37So the last feature that I wanted

7:38to cover in this particular video is the customized sound.

7:43So I'm not sure if you can hear on my desktop,

7:45but I'm actually getting some custom audio here

7:48from this alarm 3 sound.

7:50So the New-BurntToastNotification

7:52command, with its many different parameters,

7:55offers a dash sound parameter.

7:58And this allows you to specify some built-in sounds.

8:00Again, you can't specify a custom sound.

8:02But if I hit Control-Space, you can

8:04see that there are a series of built-in bounds

8:08that I can select from.

8:09So maybe I'll choose alarm 7.

8:11And if I were to put F8 on that and unmute,

8:15you can see that that sounds a little bit different than what

8:18the default Windows 10 notification sounds like.

8:22That's just an introduction to some

8:23of the core features in the new BurntToast notification

8:27commands, such as how would you customize the sound,

8:29customize the logo, as well as provide custom headers

8:34on your notifications.

8:36I hope this has been informative for you,

8:38and I'd like to thank you for viewing.

Enabling Snoozing and Adding Custom Buttons on Notifications

0:04Hi, guys, and welcome back.

0:06We've taken a look at some of the more advanced features

0:08in the BurntToast PowerShell module,

0:11and I'd like to continue that trend

0:13by taking a look at a couple of other options

0:15that allow you to create additional buttons on top

0:19of your BurntToast notifications.

0:21Let's jump over into Microsoft Visual Studio code

0:24here and get started.

0:26Now if you're following along with the GitHub companion

0:30repository, all the PowerShell notifications here,

0:33go ahead and open up the folder 05 Enable Snoozing and Add

0:38Custom Buttons on Notifications.

0:40And that's exactly what we're going to do here,

0:43So the readme just really quickly

0:44covers our learning objective here.

0:47But if we close that and open up the script.ps1 file--

0:50I'll hit Control-B once again to open up our screen there.

0:54And the first thing that I wanted to do

0:56is point out the snooze and dismiss switch parameter.

1:00So we looked at another switch parameter earlier called

1:03suppress pop up that allows you to suppress the pop up

1:06in the lower right hand corner of the Windows operating system

1:10and instead send the message directly

1:12or the notification directly into the Windows Action

1:16Center when I hit Windows-A as the keyboard shortcut.

1:21Now we're going to look at a different switch parameter--

1:23again, a switch parameter being a parameter

1:25that we don't have to pass a value into.

1:27It's either present or not present.

1:29And that parameter is called snooze and dismiss.

1:32So so far, what we've taken a look

1:34at is how to create kind of static and dynamic

1:37notifications that have text on them.

1:39However, what if you wanted to take

1:41some kind of action in response to one of those notifications

1:46popping up?

1:47Well, one of those things might be something

1:48like a meeting reminder.

1:50Maybe you want to use a PowerShell script to remind you

1:53that you've got meetings at particular times of the day.

1:56Maybe you want to build a custom email client or a custom chat

1:59client that integrates with Slack

2:01or some other kind of chat system.

2:03And using PowerShell, you can integrate those applications

2:06with the Windows notification subsystem

2:08so that you can get notifications just like you

2:11would from any native app.

2:13So if we specify the snooze and dismiss parameter here,

2:17this is just a really simple way to get

2:19us some functionality that tells us, hey,

2:23your meeting is starting in 10 minutes.

2:26So now I have two buttons on top of the notification

2:29that we did not have before.

2:30So I can either just dismiss the notification immediately,

2:33which will remove it from my list of historic notifications,

2:37or I can select a snooze time anywhere from five minutes

2:41all the way up to a day, and I can click the snooze button.

2:45And that will snooze it for that amount of time.

2:48Now that's a pretty useful feature,

2:49just being able to snooze the notification and say,

2:52you know what?

2:52I know that's important, but I'll

2:54go ahead and get back to it at some point in future.

2:57Now another even more useful integration capability

3:01that's offered by BurntToast is the ability

3:03to create custom actions or custom buttons

3:06on the notification post.

3:10So to do that, what we're going to do

3:12is take a look at this new parameter--

3:15yes, I know, another parameter on BurntToast notification.

3:18It's a very complex command with a lot

3:19of different capabilities, but bear with me.

3:22But if we take a look at this dash button parameter here,

3:25then you'll notice that it takes an iToast button

3:28array of objects as input values to that parameter.

3:35So how do you get one of those iToast button objects?

3:38Well, what we need to do is take a look

3:40at the New-BTButton command, which,

3:44of course, is part of the BurntToast PowerShell module.

3:48So if I expand up my terminal here and just do

3:50Get-Command -module BurntToast again,

3:54you'll see that one of those commands that we looked

3:56at earlier when we were kind of exploring and inspecting

3:59the module is New-BTButton.

4:02So how do we actually use that command?

4:04Well, if we just let the intellisense do the work for us

4:07here, we do New-BTButton and then put

4:10a dash to specify a parameter.

4:12And you can see that we have these options here

4:14to do either snooze or dismiss separately

4:17like we looked at earlier.

4:19Or we can specify a custom argument

4:23along with what's called an activation type, which is

4:25exactly what I have done here.

4:27So imagine the following scenario.

4:29Let's say that you're using a cloud platform like Microsoft

4:33Azure or maybe Amazon Web Services,

4:35and you are running a bunch of virtual machine infrastructure

4:38up in the cloud.

4:40And let's say that one of your colleagues

4:42is going through the list of virtual machines

4:44and is trying to do some kind of cost optimization work.

4:47And they say, hey, I'm going to stop this virtual machine

4:50that's called production because, you know, everybody

4:52wants to stop a virtual machine named production because that's

4:54not going to cause any problems, right?

4:56Well, let's say that you want to get some kind of notification

5:00when an alarm in the, let's say, the CloudWatch service

5:04in Amazon Web Services is triggered,

5:06indicating that that machine has gone offline.

5:09Well, we can use new BurntToast notification

5:12to create a message basically saying, hey,

5:15this virtual machine named XYZ 123 has been shut down.

5:20But then we want to be able to take

5:22some kind of immediate action in response to that.

5:25We need to get that virtual machine back up

5:27and running so that it is running my production

5:29application, right?

5:30Well, what you can do is specify the activation type of protocol

5:35on the button that you're creating for the notification.

5:38Also, you can specify the content parameter,

5:41and that is going to determine the text that

5:43is shown on this custom button.

5:46Additionally, under the arguments parameter

5:48here, we can specify a URL that we

5:51want to invoke as a result of clicking this button.

5:56So then what we need to do is assign that result

5:58of that New-BTButton over to a variable

6:01so that we have a reference to refer to that button.

6:03So I'm just going to call it a button,

6:05but again, it's just a variable name.

6:07You can call it whatever you want to, maybe AWS button.

6:10And then over here on the New-BurntToastNotification

6:13command, we need to pass in a reference to that button.

6:18By simply dereferencing the variable using the dollar

6:23variable name [INAUDIBLE].

6:24So let's go ahead and select both lines seven and eight

6:27here.

6:27So I'll just do Shift-Down Arrow a couple of times.

6:30Select both those lines.

6:31Hit F8 in VScode.

6:33And as you can now see, we've got this nice notification

6:37down here saying virtual machine outage.

6:39VM named XYZ123 has been shut down.

6:42And what's cool is that I've got this button here.

6:45But instead of being snooze or dismiss,

6:47it's this custom button that says open console.

6:49Or maybe I should have changed it to open AWS console.

6:52And one other thing I probably should have done too,

6:54now that I think about it, is I probably

6:55should have customized this BurntToast icon to be like AWS.

6:58That was a little bit more customized.

7:00But I'll leave that to you guys for your own exploration.

7:03So if I were to click the Open Console button,

7:06that is now going to pop open my web browser

7:09and navigate me directly over to the AWS Management

7:14Console, which is right now on my other screen.

7:16So I apologize for doing that.

7:20So that's just a quick introduction

7:21to some of the customization that you

7:23can do using custom actions, custom buttons, as well as

7:26snoozing, reminders from the Windows Action Center.

7:31I hope this has been informative for you

7:33and I'd like to thank you for viewing.

Adding Context Menus to Notifications

0:04Howdy, guys.

0:05Welcome back.

0:06Now in the previous video, we took a look

0:08at some really cool customization features

0:10that allow you to create interactive notification

0:14Toasts on the Windows 10 platform using the BurntToast

0:18PowerShell module.

0:19Now we're going to continue this customization trend

0:22in a slightly different way.

0:24So instead of creating buttons, we

0:26can actually create what are called context menu

0:29items on a notification Toast.

0:32So let's jump in over to Microsoft Visual Studio

0:35Code, our editor, and take a look at how to [AUDIO OUT]..

0:39So for starters here, let's head over to the Control-Shift-E.

0:44We'll open up the Explorer on my keyboard here.

0:47And I'm under this 06 folder Add Context Menus to Notifications.

0:52And of course, that is exactly what we're going

0:54to be doing in this video--

0:56adding additional capabilities to our notifications.

0:59So in the previous video, we took a look

1:02at how to use the button parameter on the new BurntToast

1:07notification command.

1:09Now the feature that we're about to look at right

1:11now is actually not available on the new BurntToast notification

1:15command.

1:16Instead, if you scroll down here in our script.ps1 file

1:19down to line number 13, you will notice

1:22that we are using a different command called

1:25Submit-BTNotification.

1:28Now I'm not entirely sure why this capability of context

1:32menus is not available on the new BurntToast notification

1:36command. and However, it's very possible

1:39that the module will change as it continues

1:42to develop in the future, and maybe we'll

1:44see that option be available.

1:46However, for now, we are on the, I

1:49think, 0.8.2 version, yep, of the BurntToast PowerShell

1:54module.

1:55And as of right now, if we want to use this context menu

1:57feature we must do it using the Submit-BTNotification command.

2:03All right, so how do we actually get to this point?

2:05Well, let's close our integrated terminal there.

2:07And I want to call your attention

2:09to yet another command inside of the BurntToast PowerShell

2:13module.

2:14And that command is called New-BTContextMenuItem.

2:19Thanks to the verb dash noun nomenclature

2:22for command naming in PowerShell,

2:24it should be pretty obvious just from plain English what

2:27this command does.

2:28It creates a new context menu item for the BurntToast

2:31PowerShell module.

2:32Now there are a few different parameters

2:34here that we want to take a look at.

2:36Now very similar to the buttons that we created

2:38in the previous video, we have this activation type

2:40of protocol.

2:41So basically, that's going to leave it up to the operating

2:43system to look at the protocol that

2:46is specified in the argument's URI and take action there.

2:50So of course, we're using HTTPS here,

2:52and that's going to pop open inside of our default web

2:55browser.

2:57So the arguments parameter is, of course,

2:59the URL to whatever web page we want to pull up.

3:04And then over here, we've got content,

3:06which is just a name for the context menu item.

3:09So it's just the text that's going to show up

3:11for the context menu item.

3:13Now what's cool is that you're not limited to just one context

3:16menu item.

3:16You can actually create several different ones.

3:19So let's say that we wanted to be able to quickly respond

3:22to events that happened inside of our cloud accounts

3:25using these context menu items.

3:28So maybe you're doing some work in AWS,

3:30some work in Google Cloud, and maybe some work

3:33in the Microsoft Azure portal.

3:34And so you want to have shortcuts

3:36to these directly in your notification toasts

3:38so that when one of these events occurs,

3:40you can really quickly pull up one of those consoles

3:44and take some kind of action in it.

3:45Now if it was me, I'd probably use the PowerShell module

3:48for each of those cloud platforms

3:49to perform whatever automated actions I needed to,

3:52but you choose the right tool for your preference.

3:57Now something that's a little bit different here

3:59with the Submit-BTNotification.

4:01is that we have to construct what's called a BurntToast

4:05content object.

4:07And BurntToast content object takes a couple of parameters.

4:14So one of those is going to be an Actions object.

4:17So we have to use the New-BTAction command

4:19to construct one of these action objects.

4:22And one of the parameters on BTAction New-BTAction,

4:26is called context menu items.

4:28And yes, there is an S at the end indicating

4:30that it accepts an array.

4:33So if I hit Control-Space here, you'll

4:34see that we have an array as indicated

4:37by the square brackets here of Toast context menu items.

4:41And those are the objects that are

4:43being emitted by the new context menu item command

4:47up here on lines 1, 2, and 3.

4:50So what we're going to do is basically just

4:52assign each of those contexts menu items to a variable.

4:55Of course, you could just assign all of them

4:57to an array, a single array, and then pass the array in as well.

5:00But again there's multiple ways to do things.

5:03I just happen to use three separate variables

5:05for this purpose.

5:06But once we construct the action object,

5:08we assign that to a variable.

5:10And then we also need this thing called a visual object.

5:13I'm not really quite sure why you need this

5:15because you're not really configuring

5:17anything that's perceivable by the end user in this case.

5:20But you do have to create this thing called a binding

5:22and then pass it in.

5:23And that gives you a visual object.

5:26And then that gets passed into New-BTContent as well.

5:29So once you've constructed this New-BTContent that contains

5:33the visual and the action--

5:35and the action, of course, contains child references

5:38to the context menu items--

5:39then you can finally submit the BTNotification.

5:43And pass in that content object, and you

5:47should see something along the lines of this down here.

5:52Now this looks pretty unexciting, right?

5:54It just says Windows PowerShell new notification.

5:56Of course, we could further customize that with some text.

5:58What I want to call your attention to here

6:00is actually our context menu.

6:02All the context menu items that we created

6:04are under this little gear icon or this little Settings icon.

6:08So if we click on the Settings icon,

6:10you can see that I've got these context menu items that

6:13allow me to open up the AWS Management Console, the Google

6:17Cloud console, as well as the Microsoft Azure portal.

6:20So whenever you create those context menu items,

6:23they're going to show up right here under that little gear

6:26icon.

6:26So be aware of that.

6:29I'll hit Windows-Escape and close my Windows magnifier

6:32there.

6:33And of course, because we have that notification

6:35persisted over here in our Action Center

6:37when I hit Windows-A to pop open my Action Center,

6:41I can still always refer back to that little gear icon up here

6:45in the Action Center as well.

6:48So if for some reason you've closed that notification or you

6:51missed it before it disappeared, then you

6:53can always hit Windows-A, pop open the Action Center,

6:56and go back and refer to the context menu.

6:59There's a lot of really rich capabilities

7:01that you can perform here.

7:02You could even change one of these URLs

7:04in the arguments of the context menu item to call a custom API,

7:08for example, that's maybe hosted internally or even just locally

7:11on your development system and perform

7:14of some automation tasks as part of your own custom API as well.

7:18This is some really cool functionality.

7:20I really like the fact that you have multiple choices.

7:22You've got buttons, got context menu items.

7:24You can customize the text and the logo and the headings.

7:27As you can see, there's a lot of really cool

7:29functionality inside of these Windows 10 notification posts.

7:32I hope this has been informative for you,

7:34and I'd like to thank you for viewing.

Building Progress Bars with Windows Notifications

0:04Hey hey, guys, and welcome back.

0:06We're moving right along.

0:07We've covered a lot of really cool stuff--

0:08how to create notifications, how to add headings and custom

0:12sounds, how to add buttons and snoozing capabilities,

0:16and even add context menu items to your Windows 10 notification

0:20toasts as well.

0:22Now in this video, our last major video

0:24of functionality on the BurntToast PowerShell module

0:28is going to cover the progress bar's capability.

0:31Yes, there's even more functionality

0:33we still haven't explored yet.

0:34So let's jump over into Visual Studio code here.

0:38And if you're following along in the companion GitHub repository

0:41over at github.com/cbttrevor/powershell

0:43notifications, then go ahead and open up the 07 directory.

0:50And our objective here is to learn

0:52how to create progress bars.

0:54Now why would you want to create a progress bar?

0:56Well, progress bars can be used to indicate

0:58kind of a status of any kind of long running task.

1:01So you have status bars in your web browser

1:04when you're downloading large files.

1:06If you're using a BitTorrent client to download something

1:09like an Ubuntu ISO, which I do on a periodic basis,

1:12you know, I get a progress of how much of the file

1:15has been completed, how much more is remaining,

1:18things like that.

1:19And so you might want to have those kind of indicators

1:22if you're doing backup jobs.

1:24Like, if you're backing up maybe 10 terabytes of data,

1:27maybe you want to know status intervals as to how

1:31that backup job is going.

1:33Or maybe you're doing some cleanup tasks

1:34in Microsoft Active Directory, or maybe you're

1:36cleaning up a resource groups in Microsoft Azure

1:39to reduce the number of resources

1:41that you're being billed for inside of your cloud platform.

1:45Well, you can use notifications to get progress updates

1:49on your scripts in PowerShell.

1:52So go ahead and pop open the script.ps1 file here.

1:55And that's going to be in the 07 Build Progress Bars directory.

1:59And let's take a look at an example.

2:01Hit Control-Tilde, and that'll just close the terminal here.

2:05Sorry there.

2:06Close the VS Code terminal.

2:08And basically, what we're going to be doing here

2:11is mocking up a scenario where we

2:13want to clean up computer accounts in Microsoft Active

2:16Directory.

2:17And maybe you've got hundreds or thousands of computer accounts.

2:20And so, you know, this script is going

2:22to run for maybe 10 or 15 minutes.

2:24I'm not exactly sure how long it'll take.

2:25I don't actually have an Active Directory instance

2:27up and running locally, which is why we're

2:29kind of mocking this up here.

2:30So what I've done is I've created

2:32a variable with an array of computer names

2:35that we want to clean up in our Active Directory instance.

2:40Now as we iterate over these in a--

2:42over each array here, we want to get some indication

2:46of how many have been cleaned up and how

2:49many are remaining as a percentage from 0% to 100%,

2:54right?

2:54So when that job is 100% done, then we can-- you know,

2:57we're done.

2:58We move on with our lives.

3:00So we've got 1, 2, 3, 4, 5, 6-- six computer objects

3:05here in our computer name array.

3:07So if we just hit F8 to populate that array,

3:11populate that variable in our PowerShell session,

3:14you've now got this computer names array.

3:15We can just spit it out to the terminal there.

3:18Or we can grab the built-in count property

3:20in PowerShell, which tells us how many items

3:23are in the array.

3:24So there's six items in the array.

3:26So if we are on item number two out of six, that's 33% done.

3:30If we're on item four out of six,

3:32that's 66% done, et cetera, et cetera.

3:35So how do we use the BurntToast PowerShell

3:37module to indicate the progress of this long running task?

3:42Well, basically, what we need to do is, first of all,

3:44we need to calculate the percentage of the completion.

3:48So basically, what we would do is

3:50for each item in the computer names array,

3:53we would grab the first computer name and operate on that one,

3:57then go to the next one and so on and so forth.

3:59So for-each is just a nice looping construct

4:00in PowerShell.

4:02And in order to calculate the percentage of completion,

4:04we need to take the index of--

4:07we have this method on arrays in .NET or in PowerShell in this

4:12case--

4:12index of the current item, which is the dollar item

4:16variable here in my for-each loop.

4:18And we need to add one because if we do index

4:21of the first computer here--

4:24let's actually just grab that, say

4:26computernames.indexofdesktopx.

4:33Then you'll see that we get a 0.

4:34And that's because arrays in most programming languages

4:38are zero-based.

4:39However, we have six items.

4:42And so we need to start at 1--

4:431, 2, 3, 4, 5, 6-- to get our percentage complete.

4:46So what we need to do is basically just

4:48add 1 to the index of the current item.

4:51So on the first item, instead of giving us a 0,

4:53it'll give us a 1 instead.

4:56So that way, when we divide by the total number of computers

5:00in this list, computernames.count,

5:03we'll get an accurate portrayal of the percentage.

5:08So now as it pertains to the BurntToast module specifically,

5:11we're going to be going back to the new BurntToast notification

5:14command instead of using submit BT notification as we looked

5:18at in the previous video or working with context menu

5:21items.

5:22Now the new BurntToast notification command

5:24has yet another parameter here called Progress Bar.

5:28And the Progress Bar parameter expects

5:30an array of progress bar objects, adaptive progress bar

5:34objects.

5:35I don't know why that's the type name,

5:36but it has something to do with the core

5:38Windows APIs that are being wrapped by this module.

5:42So in order to generate one of those adaptive progress bar

5:46objects, we need to use another command in the module called

5:51new BT progress bar.

5:53So if we do Get Command, module BurntToast as usual,

5:57we'll see that there is a command called new BT progress

6:00bar.

6:01So as we start typing out that command, new BT progress bar,

6:05and put a dash, you can see that there

6:07are a few different parameters that are available on it.

6:11So value is going to be our current percentage

6:14of completion.

6:15And then value display is going to be

6:17the total number of objects that we are operating on.

6:21So in this case here, our value display

6:23is going to be computernames.count,

6:25and that's going to give us in this case

6:27because we have six array elements in the computer names

6:30variable.

6:31And then because we've already calculated the percentage

6:33and assigned that to a variable called $percent,

6:35I can simply pass that in to the value parameter.

6:41Now the progress bars do you have a custom title on them

6:44as well.

6:44So you can just use the title property there.

6:47And then you can also provide a custom status

6:49for the current state of the process.

6:52So we looked at earlier .NET string formatting in PowerShell

6:55and how we can create dynamic strings in, I think,

6:58the third video in this skill, where we created our first

7:01notifications using the BurntToast module.

7:04And what we're doing is we're basically

7:06constructing this dynamic string where

7:08we're passing in the current item

7:10that we're iterating on in the for-each loop in PowerShell.

7:13So we're basically just going to substitute in the computer name

7:16that we're currently operating on into the string template

7:20here.

7:21So that's going to give us a progress bar object,

7:24and then we just pass that progress bar

7:25object into the new BurntToast notification.

7:28Now there is a specific parameter

7:29I want to call out here, and this

7:31is called unique identifier.

7:33So BurntToast has a unique identifier parameter

7:35so that you can update the status of an existing

7:38notification.

7:40So if we were to leave that parameter off--

7:43and I'm also going to tack on the silent parameter

7:46to repress the audio from occurring

7:49even though I have it muted.

7:50Just a good practice because when we do this for-each loop,

7:53we're going to be triggering lots

7:54of different notifications.

7:55So if I just hit F5 on that, you'll

7:57see in the lower right hand corner of my screen

8:00here that we are getting separate--

8:05it won't be obvious right here, but when we open up the Action

8:08Center, you'll see this.

8:09We're actually getting separate notifications

8:11for each of the computer objects that is being,

8:14quote, "cleaned up" in this instance.

8:16So if I hit Windows A, pop open the Action Center,

8:19and just scroll up here, you'll see

8:20that each computer account that we're iterating over

8:23is actually generating a whole notification of its own.

8:27So what we want to do is actually reduce

8:29that duplication in this case.

8:31And instead, what we want to do is consolidate all of those

8:36into a single notification that gets updated

8:39as the process continues.

8:41So I'm just going to hit clear all notifications so that we

8:44can start fresh here with no notifications in the Action

8:47Center.

8:48So now let's go ahead and do Control--Z to bring back that

8:51unique identifier parameter.

8:53And you can really call it whatever you want to.

8:55It's basically just a unique name for this particular task.

8:58If you're running lots of tasks simultaneously,

9:00you probably want to use some kind of dynamic naming

9:02convention where you have a randomized identifier

9:05for each one of those.

9:06But I'm just calling this one clean up for now.

9:09And then let me change the interval here to 1,000.

9:13So I'm basically just using a start sleep command

9:15to kind of emulate a slower running ask.

9:18Let me actually do 1,500, 1.5 second.

9:21So if I hit F5 and rerun this, now

9:24that we've brought this unique identifier back,

9:26you'll see what changes here is that now, we

9:30have, in the Action Center here, instead of having

9:34a brand new separate notification,

9:35we're actually just updating the one notification

9:38that we have here.

9:39So we've kept this a lot cleaner.

9:41And even though we're still displaying new notifications

9:44each time, it is ultimately behind the scenes

9:47updating just that one.

9:49I'll Windows Escape here, close my magnifier.

9:52And I just wanted to kind of show you just an introduction

9:55to the progress bar.

9:56This is a really nice bit of functionality in the BurntToast

9:58PowerShell module that, as I understand it,

10:00I think this is a fairly new capability.

10:02So anytime that you're building out some kind of long running

10:05script that's going to run for maybe several minutes

10:07or maybe even several hours in some cases-- maybe

10:10you're building out a report, and you're

10:12pulling queries from different databases

10:14and merging data together.

10:15And you want to kind of get an idea

10:16of where your script of that and the process.

10:19Consider using BurntToast progress bars

10:21to help you accomplish that.

10:22I hope this has been informative for you,

10:24and I'd like to thank you for viewing.

Review and Call to Action

0:04Hi, guys, and welcome back.

0:06So in this final video, I just wanted

0:08to review what we've learned in this particular CBT Nuggets

0:12skill.

0:13So we took a look at the very beginning

0:14at the BurntToast module.

0:16We looked at the GitHub repository

0:18where that module is being developed as an open source

0:21project.

0:22And one of the great things about open source projects

0:24is that you can get involved in those projects.

0:27So if you have ideas for feature requests in the BurntToast

0:31PowerShell module or maybe you come across a bug

0:34and something doesn't quite work the way that you expect it

0:37to or maybe when you pass in the right parameters

0:39or what you think are the right parameters,

0:41you get an error message, and you

0:43get a bunch of ugly red text on your screen,

0:44and you're like, hey, why is this happening,

0:46you can ask questions there.

0:48The PowerShell community is actually

0:49very welcoming and very helpful, so

0:52definitely rely on those people in the community

0:55to help you out.

0:57You can also post issues on services like Stack Overflow.

1:00So if you have a question about how to use BurntToast,

1:03instead of starting a discussion over on the GitHub repository,

1:06you might want to go ahead and document that over

1:09on Stack Overflow, since that is a really popular Q&A

1:12site for software developers and engineers.

1:15So we took a look at the module, the module project page.

1:19We also looked at the PowerShell Gallery,

1:21where powershellgallery.com hosts

1:23a whole bunch of third party modules

1:25as well as vendor supported modules from services

1:28like Microsoft and Amazon Web Services and Google Cloud

1:31and lots of other very popular software

1:35tools out there in the ecosystem.

1:37And then we took a look at how to actually install

1:39the PowerShell module in our local PowerShell session using

1:42Visual Studio code and PowerShell Core

1:45addition on the Windows 10 platform.

1:47Then we dived into how to create some really

1:50basic notifications.

1:51We started out with just some static text.

1:53And then we got a little bit more

1:54advanced by creating dynamic text

1:57and adding headings to our notifications

2:00as well as things like how to suppress the notification

2:02prompt from showing up.

2:04But it can just go directly to the Action Center.

2:08Then we dived in some more advanced notification

2:10concepts-- things like how to create

2:12idles to add to our notifications

2:15as well as applying custom sounds to our notifications

2:20as well to override just the default sounds in the Windows

2:2410 platform, which can get a little boring after a while.

2:27Nice to have some choices in what kind of indicators

2:29you're presenting as part of your notations.

2:33We also took a look at how to add some custom buttons,

2:36how to do snoozing of alarms to remind you about upcoming

2:39events or things like that.

2:41Then we took a look at how to create context menus

2:43that you can add custom functionality

2:45into your notifications.

2:47And then finally, we took a look at how

2:49to create progress bars so that you can apply progress bars

2:52and get a status update very easily right

2:54there in your Action Center as to where

2:57your long running tasks are at [INAUDIBLE]..

3:01So I hope this has been an informative skill for you.

3:04If you guys have any feedback, feel free to leave a comment.

3:07And make sure that you use those voting buttons

3:09on each of the videos to thumbs up or thumbs down

3:12depending on what your opinion was of this training content.

3:16Feel free to hit me up on Twitter at pcgeek86

3:19or head over to my personal website

3:21as well, where I talk a lot about PowerShell

3:23and a lot of different techniques

3:24that you can apply to the PowerShell framework.

3:27I hope this has been informative for you,

3:29and I'd like to thank you for viewing.

What's next?

Ready to keep going?

For your team

Bring this training to your team

See how CBT Nuggets helps IT teams close skills gaps, hit compliance targets, and prove training ROI.

Book a Demo
Just need PowerShell Automation?

Learning on your own? Browse individual plans ($49/month, billed annually)

Not ready to buy?
with no purchase required. Already have an account?
Book a Demo