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.
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
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:
PS C:\work> $data[0..2] Time : 00:03:00.5083791 Application : Windows PowerShell WindowTitle : Windows PowerShell 4.0 Product : Microsoft® Windows® Operating System Time : 00:32:02.6150152 Application : Windows PowerShell ISE WindowTitle : Administrator: Windows PowerShell ISE Product : Microsoft® Windows® Operating System Time : 00:13:47.6952161 Application : Virtual Machine Connection WindowTitle : CHI-Win7 on WIN81-ENT-01 - Virtual Machine Connection Product : Microsoft® Windows® Operating System
You can then measure the data.
PS C:\work> $data | Measure-WindowTotal | sort TotalTime Application TotalTime ----------- --------- Microsoft Word 00:00:34.3653455 Notepad 00:00:34.3654881 Microsoft Management Console 00:00:37.2989472 SAPIEN PowerShell Studio 2014 00:00:51.5242522 Thunderbird 00:01:55.6696204 Windows PowerShell 00:03:00.5083791 Google Chrome 00:06:34.6744841 Virtual Machine Connection 00:13:47.6952161 Windows PowerShell ISE 00:32:02.6150152
Or see how much time you spent on Facebook.
PS C:\work> $data | Measure-WindowTotal -filter facebook Application TotalTime ----------- --------- Google Chrome 00:03:23.1318619
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.
Awesome work Jeff! Thank you!
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.
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.