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 “Friday Fun: Timing is Everything”

Friday Fun: Well That’s a Fine ToDo!

Today’s Friday Fun isn’t exactly groundbreaking but you might find it useful in your PowerShell script development process. You might even learn a little something about the PowerShell ISE which is really the point of these articles anyway. How many times have you been working on a script or PowerShell tool and know that you’ll have to write some section of code but aren’t ready to tackle it now? Hopefully you are at least savvy enough to insert a comment reminding you what you need to do. So why not make this simple step as easy as possible in the PowerShell ISE?

Continue reading “Friday Fun: Well That’s a Fine ToDo!”

Friday Fun: Git Tip of the Day

This year I’ve really taken to learning Git and how to incorporate it into my daily work routine. If nothing else this has been a great reminder about what it is like to learn something totally new and foreign. I’ve learned quite a bit, but am far from considering myself a master.  Git is a big topic so I’m always looking for new ways to learn and use it. Continue reading “Friday Fun: Git Tip of the Day”

Friday Fun: A Better Test-WsMan

I saw a question on Facebook about how to get Test-WsMan to return a simple Boolean result. The Test-Connection cmdlet has a -Quiet parameter that makes this possible. But Test-Wsman does not.  Certainly, you could script a comparable outcome. Here’s one way: Continue reading “Friday Fun: A Better Test-WsMan”

Friday Fun: Tweaking the PowerShell ISE

Today’s fun is still PowerShell related, but instead of something in the console, we’ll have some fun with the PowerShell ISE. One of the things I love about the PowerShell ISE is that you can customize it and extend it.  My ISE Scripting Geek project is an example.  But today I have a simple example that you can try.

When I’m training or creating courses for Pluralsight, I am often in the PowerShell ISE and it would be helpful to highlight the line of code I am going to run. But I don’t want to muck around with a mouse. So I have created an ISE shortcut to select the current line.

The ISE has an object model that has a root of $psise which is automatically created when you launch the ISE. I won’t go into the entire structure now. For our purposes we want to take advantage of this method:

$psise.CurrentPowerShellTab.AddOnsMenu.Submenus.Add()

This method takes 3 parameters, the text to display, an action scriptblock and optionally a keyboard shortcut. If you don’t want to use a parameter, use $Null in its place. Sometimes I create menu items that don’t have keyboard shortcuts so I’ll use $Null. But in this case a keyboard shortcut is the primary purpose.

You can use any combination using Ctrl, Alt, or Shift along with function keys (F2) and alphanumeric characters. I’m going to use Ctrl+L because it is unused. If they keyboard shortcut is already used, you’ll get an error when you run the command.

I’ve posted a short script on GitHub to do the job.

Once I run this script, I have a new menu shortcut.

image

If you make a mistake anywhere or want to re-run the command you’ll need to open a new PowerShell tab or restart the PowerShell ISE and try again.

I expect at some point I’ll incorporate this into the ISE Scripting Geek module, but for now it is separate.  For now, I’ll insert the commands into my PowerShell ISE profile script. In the ISE run this command to edit it:

If you’ve never created it you’ll get an error message. The ISE profile script will be something like  C:\Users\Jeff\Documents\WindowsPowerShell\Microsoft.PowerShellISE_profile.ps1.

Enjoy your weekend.