PowerShell Reminder Jobs

timerThis is something that might be better suited to one of my Friday Fun columns, but I’m enjoying this so much I couldn’t wait to share it. I don’t know about you but I spend much of my day in PowerShell or at least with a PowerShell session running. I have an ongoing quest to do as much as I can from PowerShell. This includes just about any sort of task that might be automated.

In the past I’ve blogged about my tickle system that run when I start PowerShell. But often I have short term tickler or reminder needs. For example, since I work at home I may need to remember to switch over the laundry or that I have a phone call at 2:00PM. Sure, I could set up calendar alerts in an email client but I’d rather have something as quick and easy as a PowerShell command. So I wrote this script, New-Reminderjob.ps1.

In short, the script creates a background job that will use the MSG.EXE command line tool to display a message to myself. The job action sleeps the specified number of seconds and then runs my MSG.EXE command. I could have used a variety of ways to display the message, but MSG.EXE is built in and I didn’t see any reason to re-invent the wheel.

The script, which you could revise into a function if you want, requires the reminder text and then when to “deliver” the reminder. You can specify a number of minutes, the default is 1, or a date and/or time. If you specify a time like “9:00AM” the script will assume you mean 9AM today. The script converts your start time into a number of seconds it has to wait and builds that into the job scriptblock.

When the time comes I get a popup message like this.
msg01
The message will automatically dismiss after about 1 minute. Or I’ve configure my script to allow you to require that you acknowledge the message through the -Wait parameter. This is useful for important reminders you want to make sure you don’t miss.

Because I might have several daily reminders, I wanted an easy way to identify them. One thing I did with my script is to give all of my reminder jobs a custom name that starts with ‘Reminder’. I use a regular expression to find the number from the most recent reminder job and increment it by one. The other useful step is that I added some custom properties to the job object itself. These properties embed values from the script into the job object. Now I can do interesting commands like this:

msg02

The custom properties have no effect on any other job objects. If I find myself using these properties a lot, I might create some additional functions to save some typing.

This system is meant for ad-hoc, daily reminders to myself which is why I didn’t use scheduled jobs. I didn’t want to have to deal with cleaning up a bunch of one time jobs. These reminder jobs only last for as long as my PowerShell session is open. But be aware, that each running reminder will start a new PowerShell process so I wouldn’t recommend setting this up with dozens of reminders. Actually, if you need that many reminders you either need to get a new job or an assistant!

I hope you’ll try it out and let me know what you think or where you think it can be improved. Enjoy!

Browse TrainSignal Courses with PowerShell

talkbubble-v3It took longer than I expected, but my latest course for TrainSignal is now available. PowerShell v3 Essentials is targeted for IT Pros with little to no PowerShell experience. This is the course that will get you up and running in short order. I developed the course so that an IT Pro could be effective with the PowerShell console, using many of the new features found in PowerShell 3.0. One of those features is the Invoke-WebRequest cmdlet. I thought I’d share a version of a demonstration I did for the course on using Invoke-WebRequest to browse the TrainSignal course catalog.

In case you didn’t know, all of TrainSignal’s courses are now delivered online on a monthly subscription basis starting at $49/month. Their site has all the pricing information you need. But you can also start with a 3 day free trial. Oh, and lessons can be viewed offline as well. Anyway…using Invoke-WebRequest I can “scrape” the TrainSignal courseware page using PowerShell. Here’s my sample script.

The script saves the results from Invoke-WebRequest to a variable. In looking through the raw html I learned how the links were formatted and discovered that I only wanted links that started with /Course. I also figured out that the link objects had instructor and course information that could be parsed out of the OuterText property so I reformat the data into something more object-like.

I did this so that I could push the results to Out-Gridview displaying the courses.

get-trainsignalIn PowerShell 3, Out-Gridview can pass objects back to the pipeline, so I can select a few courses that look interesting, click OK, and the links will open up in my web browser.

I had a lot of fun creating this course and hope you find it worth your investment. Let me know what you think. And if there is a course you’d like to see me create, especially PowerShell related, let me know that too.

 

TechDays SF Presentations

TechDays_logo250 Last week I presented a number of sessions at TechDays in beautiful San Francisco. Met some great people and had a great time. I presented 4 talks, almost all of them PowerShell-related. Actually, they all had some type of PowerShell content. I’m happy to share my session slides and PowerShell demonstrations. Most of the demonstrations are not full-blown scripts but command examples, except for those things labeled as functions. If you did not attend TechDays, you are still welcome to download the material, although without the context of the live presentation some of it may not make sense. I hope you can make it next time.

File and Folders with Powershell 3
If you manage file servers and aren’t using PowerShell, you are working much too hard. Or if you are using PowerShell v2 you are still working pretty hard. Fortunately PowerShell v3 along with Windows 8 and Windows Server 2012 offer a much better solution. This session will demonstrate how to provision and manage folders, files and file shares using PowerShell from a Windows 8 client. With a little up-front work, you ‘ll be able to create provisioning scripts to deploy a new file share in seconds.

10 PowerShell mistakes, trip-ups and traps
Windows PowerShell is a language and management technology that many IT professionals, including developers, think they understand. Yet very often they get caught up in pre-conceptions and misinterpretations, usually based on prior experience with scripting or development. This session will explore the 10 most common mistakes and traps that people fall into with PowerShell and how to avoid them.

Troubleshooting Active Directory with PowerShell
Active Directory is one of those technologies that when it works, nobody notices. But when it doesn’t work, everyone does. Fortunately, Windows PowerShell and Windows Server 2012 make a terrific troubleshooting tool. In this session we’ll look at some common Active Directory problems, how to diagnose them and in some cases resolve, all with Windows PowerShell.

Building a Windows 8 Hyper-V lab
We all know the benefits of testing in a non-production environment. But sometimes resources are limited and having a test setup seems like a lot of work. But now that Windows 8 includes Hyper-V, you can setup a lab environment in very little time. This session will guide you through setting up a Hyper-V based test lab and how to get the most out of it using the PowerShell management tools.

If you didn’t catch me in San Francisco, I’ll be at TechMentor this fall in Las Vegas. More on that later. There’s a chance I’ll be back to the West coast later this year for more PowerShell goodness. Keep an eye on the blog for announcments. Or if your company is looking for training, let’s talk.

TechDays San Francisco

talkbubble-v3I’m very excited to announce that I’ll be presenting at TechDays San Francisco this year. The event runs May 2nd and 3rd. You can find the schedule here. Registration will be forthcoming. Seating will be limited so you won’t want to delay once it opens up.

As you might expect I’ll be talking PowerShell, plus a few other topics I hope you’ll find interesting. Everything is subject to last minute change but here are my current plans.

10 PowerShell Mistakes, Trips and Traps and How to Avoid Them

Windows PowerShell is a language and management technology that many IT professionals, including developers, think they understand. Yet very often they get caught up in pre-conceptions and misinterpretations, usually based on prior experience with scripting or development. This session will explore the 10 most common mistakes and traps that people fall into with PowerShell and how to avoid them.

File and Folder Provisioning with PowerShell and Windows Server 2012

If you manage file servers and aren’t using PowerShell, you are working much too hard. Or if you are using PowerShell v2 you are still working pretty hard. Fortunately PowerShell v3 along with Windows 8 and Windows Server 2012 offer a much better solution. This session will demonstrate how to provision and manage folders, files and file shares using PowerShell from a Windows 8 client. With a little up-front work, you ‘ll be able to create provisioning scripts to deploy a new file share in seconds.

Troubleshooting Active Directory with Windows PowerShell

Active Directory is one of those technologies that when it works, nobody notices. But when it doesn’t work, everyone does. Fortunately, Windows PowerShell and Windows Server 2012 make a terrific troubleshooting tool. In this session we’ll look at some common Active Directory problems, how to diagnose them and in some cases resolve, all with Windows PowerShell.

Building a Windows 8 Hyper-V Lab

We all know the benefits of testing in a non-production environment. But sometimes resources are limited and having a test setup seems like a lot of work. But now that Windows 8 includes Hyper-V, you can setup a lab environment in very little time. This session will guide you through setting up a Hyper-V based test lab and how to get the most out of it using the PowerShell management tools.

As I get more details I’ll share them here, on Twitter and on Google Plus.

PowerShell Hyper-V Memory Report

Since moving to Windows 8, I’ve continued exploring all the possibilities around Hyper-V on the client, especially using PowerShell. Because I’m trying to run as many virtual machines on my laptop as I can, memory considerations are paramount as I only have 8GB to work with. Actually less since I still have to run Windows 8!

Anyway, I need to be able to see how much memory my virtual machines are using. The Get-VM cmdlet can show me some of the data.

Actually, there are more properties I can get as well.

Those values are in bytes so I would need to reformat them to get them into something more meaningful like bytes. Not especially difficult, but not something I want to have to type all the time. Now, I can also get memory information with Get-VMMemory and this is formatted a little nicer.

What I like about this cmdlet is that it also shows the buffer and priority settings.

In the end, I decided the best course of action was to build my own function that combined information from both cmdlets. The result is a custom object that gives me a good picture of memory configuration and current use. The function, Get-VMMemoryReport, is part of a larger HyperV toolkit module I’m developing but I thought I’d share this with you now.

I wrote the function with the assumption of piping Hyper-V virtual machines to it. Although I can also pipe names to it and the function will then get the virtual machine.

Once the function has the virtual machine object, it also gets data from Get-VMMemory.

Finally, it creates a hash table using the new [ordered] attribute so that the key names will be displayed in the order I enter them. I use this hash table to write a custom object to the pipeline. I could have used the new [pscustomobject] attribute as well, but I felt in a script using New-Object was a bit more meaningful. With this command, I get output like this:

Or I can explore the data in other ways. I can create an HTML report, export to a CSV or take advantage of Out-GridView.

Here’s the report for my currently running virtual machines.

The function defaults to connecting to the localhost, but I am assuming that if you have an Hyper-V server you could use this from any system that has they Hyper-V module also installed. I don’t have a dedicated Hyper-V server to test with so maybe someone will confirm this for me.

In the meantime, download Get-VMMemoryReport and let me know what you think.