Friday Fun: Tickle Me PowerShell!

I work at home for myself which means I have to act as my own assistant, reminding me of important events and tasks. And sometimes I need a little help. So why not use PowerShell? In the past I’ve used and written about using a background job to wait until a certain number of minutes have passed and then display a popup message using the MSG.EXE command line utility. The drawback to my previous approach is that if I close my PowerShell session I lose the background job. For reminders in the next 10-30 minutes perhaps that’s ok. But for longer term reminders, I need a better solution.

I don’t know why I didn’t go this route from the beginning, but I can accomplish the same result using a PowerShell scheduled job. A PowerShell scheduled job runs via the task scheduler which means it persists outside of PowerShell. All I really need are three things:

  1. The time to kick off the task
  2. The command to run
  3. A registered scheduled job object

The time to kick off is the Job Trigger. Here’s how I can create a trigger for 30 minutes from now. My reminder only needs to run once.

The command will be the MSG.EXE command.

This needs to be in the form of a script block.

In my scriptblock I’m also going to delete the scheduled job. Finally I need to register it.

When the time arrives I get a popup message on my screen.

sample popup reminder
sample popup reminder

You can configure how long the message will be displayed before it is automatically dismissed. That’s the essential part of the process. Here is the complete script to define the function, including an optional alias.

Now I can easily set reminders for myself, even something tomorrow, next week or next month. I can use the scheduled job cmdlets to manage my reminders. I wrote this with the assumption that you are setting popup reminders for yourself.

Let me know what you think.

Measuring Folders with PowerShell One More Time

I know I just posted an update to my Measure-Folder function but I couldn’t help myself and now I have an update to the update. Part of the update came as the result of a comment asking about formatting results to a certain number of decimal places. I typically the Round() method from the Math .NET class.

So I added a parameter, Round, to automatically round to a certain number of decimal points. The default is 2 but you can enter any value between 0 and 10. If you use 0 the effect is to treat the value as an integer.

The other change I made was to simplify the code. My intention when creating a PowerShell tool is not have duplicate commands, or commands that are very, very similar. In last week’s version I used a Switch statement to dynamically create properties and values. But each item was practically the same except for the unit of measurement. So instead I came up with a hash table of units.

With this I can use the hashtable key as the part of property name, and the value for formatting the result.

The property name is created on the fly for anything other than the default “bytes”.

I use the same process if the user wants the average. Here’s the complete revised function.

The results are the same, with the addition of the rounding option.

I swear this is the last change. Unless someone gives me a cool idea! Enjoy.

Creating a Hyper-V VM Memory Report

I use Hyper-V to run my lab environment. Since I work at home I don’t have access to a “real” production network so I have to make do with a virtualized environment. Given budgetary constraints I also don’t have a lot of high end hardware with endless amount of RAM and storage. So I often run my virtual machines with a bare minimum of memory. Most of the time this isn’t a problem. Still, there are times when I need to quickly see how much memory I’m using up. I can use either the Get-VMMemory or Get-VM cmdlet.

The latter cmdlet includes a bit more detail.

All of the values are in bytes which I know I could convert to MB with a custom hashtable. But I don’t want to do that all the time so I created a command to get detailed virtual machine memory.

I’ve posted versions of this function over the last few years so you may have come across earlier iterations. The major changes in this version is that I’m calculating a utilization percent of memory demand vs assigned. I also added a switch to only show virtual machines with a Low memory status, since often that’s the most important thing I want to know.

Now I can easily get information for a single VM

Or multiple:

Clearly my SQL Server needs a little attention.

I hope you’ll try it out and let me know what you think.

Advice, solutions, tips and more for the lonely Windows administrator with too much to do and not enough time.