Friday Fun: Updated ISE Scripting Geek Module

geek A few years ago I published a module with a number of functions and enhancements for the PowerShell ISE. This ISEScriptingGeek module has remained popular over the last few years. But I wrote it for PowerShell v2. I have also come up with a number of new additions to the ISE that I use to make scripting easier. So I have gone ahead and updated the module.

The new module includes most of the original features, many of which are added to a custom add-ons menu.

scriptinggeek-addon-menu

To use the module, import it in the ISE or in your ISE profile script. Once imported you can view all of the commands.

Most of the commands will have help. I’m not going to go into detail about every command and menu option. I incorporated my scripting help module as well to provide documentation on some of the validation attributes. I think you should load up some test files and try things out.

The final thing I have done is to include some ISE theme files. To import them, go to Tools – Options and click on Manage Themes. Click on Import and navigate to the Themes folder in the module directory (…\documents\WindowsPowerShell\Modules\ISEScriptingGeek\Themes). You should see 3 files. Import one or more, select it and click OK.

grayscaletheme

monoyellow-theme

vim-themeIf you have questions or run into a problem, feel free to post a comment. I especially would love to hear about your favorite features from the module.

This version requires PowerShell 4.0 or later. You can download an older version directly here: ISEScriptingGeek-v3.1 and extract to your modules directory.

UPDATE August 2015: I have moved this project to GitHub to make it easier to update and maintain. You can check it out at https://github.com/jdhitsolutions/ISEScriptingGeek along with my other projects.

 

Enjoy and happy scripting.

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.

Friday Fun: A Christmas Present for You

Over the years a number of people in the PowerShell community have shared Christmas and holiday related items. I’ve collected them and in some cases tweaked a little bit. This year I decided to wrap them all up in a module for you. This will work in PowerShell 2.0 and later.

As you look through the functions you can probably figure out what some of these functions do, but I don’t want to spoil the surprise. But here’s an example.
xmas

Grab a copy of the module and look at the commands within it.

Don’t need to run Prompt because it automatically will run when you load the module. Note that if you remove the module you won’t get your old prompt back. Simply restart PowerShell.

Hoping you have a happy and healthy holiday and a fantastic New Year.

Browsing PowerShell Commands

Whenever I’m exploring a new PowerShell module or snapin, one of the first things I do is list all of the commands found within the module.

You can specify either a module or a snapin. Use the -module parameter for both. However, for larger modules, I’ve realized I need a better way to browse the commands. For example, I might need to see them organized by verb or noun. That information is included with the Get-Command expression. I simply have to ask for it. Here’s a more thorough command and the result.

get-command-mod

I included the command type because some modules might contains cmdlets and functions. I could revise this expression and insert a sort command. But that’s too much typing. Especially if I want to sort and re-sort. Instead, I’ll pipe this command to Out-Gridview.

get-command-mod-ogv

Now I have a sortable and filterable view of all the commands. Plus, it is in a separate window so I have my prompt back and get help for listed commands. I even decided to build a quick-and-dirty function.

Because the module or snapin name can include a wildcard, I added the module name to the output. Now I have a tool to grab all the commands from a module or set of modules and I can filter and browse all I want without having to retype or revise commands at the prompt.

Friday Fun: A PowerShell Tickler

elmoI spend a lot of my day in the PowerShell console. As you might imagine, I often have a lot going on and sometimes it is a challenge to keep on top of everything. So I thought I could use PowerShell to help out. I created a PowerShell tickler system. Way back in the day a tickler system was something that would give you a reminder about an impending event or activity. What I decided I wanted was a tickler that would display whenever I started PowerShell.

This doesn’t replace my calendar and task list, but it let’s me see events I don’t want to miss right from PowerShell. As I worked through this idea I ended up with a PowerShell module, MyTickle.psm1, that has a number of functions to managing the tickle events, as I call them. From PowerShell I can get events, add, set and remove. I thought the module would make a good Friday Fun post because it certainly isn’t a high impact project but it offers some ideas on building a module and functions that I hope you’ll find useful.

The module for right now is a single file. Here’s the file and below I’ll talk about.

You should be able to copy the code from the WordPress plugin and paste it into a script file locally. You can call it whatever you want just remember to use a .psm1 file extension. The module uses some PowerShell 3.0 features like ordered hashtables but you could revise to have it run in PowerShell 2.0. Fundamentally it should work in both versions.

The events are stored in a CSV file that I reference with a module variable, $TicklePath. The default is a file called mytickler.csv which will be in your WindowsPowerShell folder under Documents. The module also defines a variable called $TickleDefaultDays, with a default value of 7. This displayed events to those that fall within that range. To use, I added these lines to my PowerShell profile.

The result, is that when I launch a new PowerShell session I see something like this (the message about help updates is from something else so disregard):
show-tickle

Here’s how it works.

The Show-TickleEvent function imports events from the CSV file that will happen within the next 7 days. Each object also gets an additional property that is a timespan object for how much time remains. The function then parses event information and constructs a “box” around the events.

I set a foreground color depending on how imminent the event is and then write each event to the console, wrapped in my border.

I purposely used Write-Host so that I could color code events and because I didn’t want the profile to write anything to the pipeline. Because the module is loaded at the start of my PowerShell session, I can always run Show-TickleEvent and event specify a different number of days. If I want objects, then I can use the Get-TickleEvent function which will import the csv events based on a criteria like ID or name. The function uses parameter sets and I create a filter scriptblock depending on the parameter set.

When I import the CSV file, I add types to the properties because otherwise everything would be a string, and then pipe each object to my filter.

These objects come in handy because they can be piped to Set-TickleEvent to modify values like event name, date or comment. Or I can pipe to Remove-TickleEvent to delete entries. The deletion process in essence finds all lines in the CSV file that don’t start with the correct id and creates a new file using the same name.

Finally, after accidentally wiping out event files, I added a simple backup function copies the CSV file to the same directory but with a .BAK file extension. You could specify an alternate path, but it defaults to the WindowsPowerShell folder.

Hopefully I won’t miss important events again, of course assuming I add them to my tickler file. I’ll let you play with Add-TickleEvent to see how that works or you could always modify the CSV file with Notepad.

If you actually use this, I hope you’ll let me know.