Tag Archives: Scripting

Historically Speaking

So I’ve recently had a need to begin using Slack. I started out using a web browser, but since there is a Windows client I decided to give it a go. This article isn’t about Slack as much as what I was curious about and how I decided to tackle the problem.

I had read a few comments about the performance of the Slack client, although they may have been in reference to using a web browser, but it actually doesn’t matter. Instead I thought, “How can I get some historical data?” You probably have similar needs for things like processes or disk space. Since I was interested in memory utilization I could have used performance counters, and perhaps I’ll write about that eventually, but for now I had a simple one line command that gave me the pieces of information I wanted to track.

Getting process dataGetting process data (Image Credit: Jeff Hicks)

What I wanted was a way to take that snapshot repeatedly throughout the day and record the results. I decided to use a PowerShell scheduled job.

I wanted a repeating task and in my case I decided to only have it repeat for an 8 hour time span. I used a hashtable of parameters to splat to New-JobTrigger.

I elected to kick off the job one minute from the time I created the trigger. I could have used a scriptfile for my command which I expanded to export the results to a CSV file with a little additional information.

All that remains is to create the scheduled job with Register-ScheduledJob.

Throughout the day, PowerShell added data to my CSV file.

The data csv fileThe data csv file (Image Credit: Jeff Hicks)

If you noticed, I suppressed type information. This was so I could easily import the CSV into Excel and do some charting.

Charting the data in ExcelCharting the data in Excel (Image Credit: Jeff Hicks)

I formatted a few columns to make a nicer graph. Although I certainly could have formatted values like the WS sum in MB in PowerShell to begin with.

My techniques here are admittedly a little ad-hoc and perhaps not completely ready for an enterprise wide data gathering system, certainly of the “poor man’s” flavor. But I hope you see how easy it is to combine PowerShell and scheduled tasks to get the job done.

You probably have questions, so feel free to ask in the comments.

What Are You?

Here’s a quick way to tell whether a given machine is real or not: check the Win32_Baseboard class. You can use either Get-WmiObject or Get-CimInstance. Notice the results from a few physical machines.

Now see the result when querying a Hyper-V virtual machine:

I don’t have any VMware available so I don’t know what kind of result that would show. I also haven’t done extensive testing with items like a Microsoft Surface. I threw together this simple function you could use.

Have fun.

Where Did the Time Go?

antique watchLike 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.

data sample

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.