Tracking Your Day with PowerShell

timer Not too long ago, I received an email with a snippet of PowerShell code and a request for assistance. The code snippet used a little .NET code to retrieve the process for the currently active window. The goal was to have a PowerShell script run, keeping track of how long a given window was active. At the end of the day you would have a report of how you spent your day, at least based on active Window titles. As you might expect, faster than you can say “shiny ball”, I was all over this.

The code to get the active window was the easiest part. But I found I needed to take into account situations where the active process was for something non-interactive. I also found you get some odd artifacts when using Alt-Tab to cycle between open applications.

Once I had a collection of objects representing the different active windows, I realized it would be helpful to have a set of tools for measuring and analyzing the data so I wrote a function for that. The end result is a PowerShell module I call MyMonitor.

The module includes a custom format file and the .psm1 file adds some custom type definitions. The main command is Get-WindowTime. This command will monitor your windows for either a specified number of minutes, until a specific datetime, or if a specific process is detected. For tracking over longer periods of time use the -AsJob parameter.

You should end up with data that looks like this:

You can then measure the data.

Or see how much time you spent on Facebook.

This is from a small sample.

My module also includes an about topic, which I’ll post here

I hope you’ll try it out and let me know what you think. Be sure to read help and examples for all of the commands.

Download the MyMonitor zip file and extract to your modules folder.

Update: this will not track Windows 8 apps like Weather or Foo & Drink.

3 thoughts on “Tracking Your Day with PowerShell”

  1. I’ve used apps that do this sort of thing, and the biggest issue is that they don’t discriminate between different uses of the same application. For instance, it says you’re using Chrome for 3 hours, but that doesn’t tell you whether it was Facebook, updating Confluence with notes, Jira with your work items, or doing research on your latest project.

    Apps like this have to understand the context of each of the monitored applications and how to differentiate work streams from each other, then report that.

    Of course the other issue is multiple monitors. If I have two or three monitors and multiple windows open, only one is active, but I may be using two others interactively – though they aren’t being counted. You need to somehow track *visible* windows.

    1. Thanks for your comments. I track window title and if you look at the examples you’ll see there are ways to filter out Facebook on Chrome from something else. But yes, there are limitations to this which is why I use it more as a general guideline and not as a true time tracker. But as with everything I post here, I hope there is an educational value and often that is the driving force. More than sharing a production-worthy tool.

Comments are closed.