All posts by Jeffery Hicks

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.

Updated PowerShell Formatting Functions

Last year I posted an article and a set of PowerShell functions to make it easier to format values. For some reason, I decided to revisit the functions and ended up revising and extending them. I modified Format-Value so that you can format a number as a currency or a number.


Format-Value help (Image Credit: Jeff Hicks)

The function is assuming you will pipe values to it.


Format-Value examples (Image Credit: Jeff Hicks)

I also wrote a new function called Format-String.


Format-String help (Image Credit: Jeff Hicks)

The nice thing is that you can apply as many or all of the formatting transformations as you want.


Format-String examples (Image Credit: Jeff Hicks)

The Replace option works by taking a hashtable and replacing each matching key with its value.


Using the Replace parameter in Format-String (Image Credit: Jeff Hicks)

One task that comes to mind where Format-String might come in handy is in building passwords.

The function contains the following aliases:

  • fp = Format-Percent
  • fv = Format-Value
  • fs = Format-String

I’m also trying something different, at least for me. Instead of posting the code here, I’ve started to use GitHub since that seems to be what all the cool kids are doing. You can find the FormatFunctions module at https://github.com/jdhitsolutions/FormatFunctions. This should also make it easier for me to post revisions, address bugs and make it easier for you to take my code and run with it. You’re still welcome to post comments here, but use GitHub for anything specific to the PowerShell code.

Enjoy.

 

Veeam Whiteboard and PowerShell

talkbubbleI’ll be live next week talking about PowerShell principles and concepts as part of the Veeam Whiteboard series. Should be a lot of fun.  I hope you’ll catch it live or on demand. You can learn more and register for free at http://www.veeam.com/veeamlive/powershell-paradigm-principles-practice.html