A Classy Christmas PowerShell Module

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.

Continue reading

Friday Fun: Timing is Everything

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.

Continue reading

Compare PowerShell Modules

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.

Continue reading

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.


About_MyMonitor

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.

What Were You Working On?

toolboxIt probably comes as no surprise that I write a lot of PowerShell code. Like you, I’m usually working on several projects at the same time, most often using the PowerShell ISE. When I fire up the PowerShell ISE I often go to most recently edited files and re-open the files I was last working on. But sometimes my list of current projects gets pushed aside by other files I might open and edit. Because I like to be lazy (I mean efficient) I decided to come up with a solution to make it easy to open files I’m actively developing.

In the PowerShell ISE you can easily load a file into the editor with the PSEDIT command.

So all I need is a way to store my active files. It is simple enough to use a text file. All the text file needs is a list of full file paths. Opening all the files can be as easy as this:

But how can I easily add a file to the list? I can use the PSISE object model to get the path for the currently active script file and add it to the file.

To remove a file from the list, it is probably easiest to simply open the current work list using PSEDIT and manually delete what I no longer need. I took these core commands and wrapped them in a set of functions. And of course, I don’t want to have to type any more than I have to so it would be handy to add some shortcuts to the ISE Add-On menu.

I ended up creating a set of functions for these key operations and incorporated them into my ISE Scripting Geek module. The module exports a global variable for my work list.

Now when I open the ISE I can press Ctrl+Alt+I and have immediate access to everything I’m currently working on. This has already saved me a lot of time and frustration.

I have moved the ISE Scripting Geek module to GitHub so check it out here. Feel free to pick and choose what you want from the module or take my commands here and create your own solution for loading your active work files. The functions for this particular feature are in CurrentProjects.ps1.

Enjoy and let me know if this starts saving you some time.