Last week I published a few of the recent PowerShell modules I’ve been working on to the PowerShell Gallery. These projects had been in a beta phase while I worked out some last minute features. I was also waiting to see if there were any issues reported by you that I might need to address. Nothing came up so I think we’re good to go. Here’s the new projects you can install from the PowerShell Gallery.
Yesterday I showed you a class-based PowerShell script. My intention was to have a little bit of fun and teach you the basics of using a class. But what I gave you was really just the first step. If you wanted to create an actual tool around a class, you will most likely want to package it into a module. I’ve done that with my Christmas class. Let me explain why and the changes I made.
For today’s fun I want to introduce you to a PowerShell project I’ve been working on. As with many of these Friday Fun projects this is something that is hardly groundbreaking but it could be fun to use and hopefully serves an educational purpose. What I have is a module called MyTimer that contains several commands designed to work with a very simple timer. In fact it is so simple you’ll probably think I’m joking.
One of the attractive features in PowerShell v5 is PowerShellGet. This module includes commands which makes it easy to discover and install PowerShell modules from the Internet, or even your network. The modules are stored in online repositories. Microsoft maintains one called PSGallery. Typically you will use PowerShell commands to find and install modules. As a quick side note, while Microsoft appears to do some degree of review using the PowerShell Script Analyzer, there is no guarantee that modules you find online will work in your environment. That’s why the repository is untrusted by default. You can still download and install but you are accepting the potential risks. But that’s not the point here. It is pretty easy to download new modules, which includes DSC resources. However, new versions can be published to the online repository. As far as I know there is no notification mechanism. So you might have to periodically check to see if there are new versions available. Which means I wrote a tool.
Like many of you the work day just seems to fly by. At the end of the day I start wondering what I really got accomplished and what I actually did all day. Well if you are willing to face the truth I have a way to help. Last year I wrote about a PowerShell module I called MyMonitor. As part of my ongoing effort to make some of my larger projects more accessible, I have revised it and published to GitHub.
The MyMonitor module works under the premise of keeping track of what window is currently active and how long it has been running. I can also extract other information using Get-Process that indicates the window title, the associated product, when the process started and when it ended. I include the processID as well, although that probably doesn’t have any practical value.
The data collection process starts with Get-WindowTime. You can specify a time duration in minutes such as 60 minutes. Or perhaps you want to collect your usage data until 4:00PM. You can do that as well. One way that I use the command is with the ProcessName parameter. The concept is that you can start an application that you rarely use. When Get-WindowTime detects the process, it terminates collection. I typically use Windows Calculator as a “flag” process. Finally, you can run all of this as a background job so that you can get your PowerShell prompt back. Just don’t close your session before you stop the job and collect the data.
The new version also includes categories. I created an XML file in the module with categories for different applications. You can have an application with more than one category. This adds another way to see where you are spending your time. More on that in a moment. When you collect your usage statistics, you’ll get an object like this for each application.
The module includes a few cmdlets for reporting and analyzing the data.
Getting a summary report
Or you can use Measure-WindowTotal to slice and dice the data.
Measuring window time by application
Measuring window time by category
You can even get a bit more granular be filtering on text in window titles.
Measuring time by window title (Image Credit: Jeff Hicks)
All of the commands in the module have complete help and examples. There is also an About topic.
The module is still a work in project. One of the items on the wish list is a better way to archive usage. This would allow you get a better idea of where your time goes on a weekly or monthly basis.
But for now, you can get the module source files from the repository on GitHub. I strongly recommend you read the About topic and help before you start using the module. Comments are welcome here but please use GitHub to report any problems or feature requests.