Making Windows PowerShell ISE “Good Enough.”

I don’t generally write a lot of big scripts, but when I do, I usually fire up the PowerShell 2.0 graphical IDE. However, every time I use it to develop a module I always get irritated by the lack of any session management. When I hack away on a module, I usually have a couple of files open. I rarely finish a module in one sitting either, so I’ll come back to it in a day or two. I don’t always leave ISE open though so when I fire it up again I have to navigate to the location (or locations) where my files are and re-open them. Another annoying situation is playing with assemblies either by loading some external ones, or by using Add-Type to create your own in-memory types/classes. Debugging these things can get annoying as once loaded or created, you have to quit ISE to “clean” memory of all your dabblings. Well, I lie when I say you have to quit ISE. Strictly speaking, you can create a new tab with CTRL+T, close the old one and load all of your scripts into the new tab. Tabs are isolated from one another and assemblies loaded in one are not available elsewhere. So, taking advantage of this trick, let me introduce:

ISE Session Tools Module v1.0

I have more features planned for v1.1 to give ISE a proper “project” based feel to it, but in the interest of shipping something, v1.0 has the following features:

  • AutoSaving of current session (files open in current tab.)
    • This can be disabled and manually controlled if desired.
  • Prompt to reload last session on ISE open
    • A hint is shown to you reminding you of some of the files you had open.
    • Press <enter> to accept the default of “Yes, reload my last session.”
  • Restarting of the current tab
    • Essentially cleaning memory and keeping your files open in the editor.
    • You get prompted for this action. Press <enter> to accept default of “Yes, restart this tab.”
  • All commands available under “Add-ons” menu for the mouse-fixated.

image

The commands exported by the module are:

  • Restart-PowerShellTab  (CTRL+ALT+R)
  • Export-PowerShellTab (CTRL+ALT+S)
  • Import-PowerShellTab (CTRL+ALT+L)
  • Enable-AutoSaveSession (CTRL+ALT+A)
  • Disable-AutoSaveSession (CTRL+ALT+X)

As you can see, they have hotkeys. This is possible because these commands are also bound to the “Add-ons” menu. I was careful to choose keys that do not interfere with IsePack if you like to use that module too.

image

Installing IseSessionTools

Extract the files  into a folder named “IseSessionTools” under <my documents>\WindowsPowerShell\Modules\. In my ISE $profile, I have the following lines at the end of the file:

Import-Module ISESessionTools
Enable-AutoSaveSession

If you want to clear your session, disable autosaving and delete the session file at ~\psise.session.clixml.

Download ISE Session Tools Module v1.0

Have fun!

blog comments powered by Disqus

About the author

Irish, PowerShell MVP, .NET/ASP.NET/SharePoint Developer, Budding Architect. Developer. Montrealer. Opinionated. Montreal, Quebec.

Month List

Page List