Friday, March 14, 2014

PowerShell ISE Color Themes

So admittedly, I'm late for the party once again. I've only recently started running PowerShell 4.0 and having come from 2.0, I am quite impressed to say the least! I won't go on about all the new features here because I'm sure you've already read about it elsewhere by now. If not, this article will fill you in: What's New in the Windows PowerShell ISE. Instead of rewriting that article, I'll talk about the not so new by now ISE themeing capability.

With PowerShell 3.0/4.0 you can now change the color of every element in the script/command panes and save these changes to an xml file for use in other ISE sessions. You can also change these elements with a script file or commands but here's the strange thing. There is no current way to use the xml file with the scripted method. Instead you must manually set the individual properties. On top of that, their xml file is less than user friendly.

Here's an example script from the scripting guys in this article Customize Colors and Fonts in the Windows PowerShell ISE. Fair warning, the color selections are hideous!


# fonts             
$psISE.Options.FontName = 'Kartika'             
$psISE.Options.FontSize = 16             
# output pane             
$psISE.Options.OutputPaneBackgroundColor = '#FFFFEFD5'             
$psISE.Options.OutputPaneTextBackgroundColor = '#FFFFEFD5'             
$psISE.Options.OutputPaneForegroundColor = '#FF000000'             
# command pane             
$psISE.Options.CommandPaneBackgroundColor = '#FFFAEBD7'             
# script pane             
$psISE.Options.ScriptPaneBackgroundColor = '#FFFAEBD7'             
# tokens             
$psISE.Options.TokenColors.item('Command') = '#FFA0522D'             
$psISE.Options.TokenColors.item('Operator') = '#FFA0522D'             
$psISE.Options.TokenColors.item('Unknown') = '#FFFFFFFF'             
$psISE.Options.TokenColors.item('Member') = '#FFFFFFFF'             
$psISE.Options.TokenColors.item('Position') = '#FFFFFFFF'             
$psISE.Options.TokenColors.item('GroupEnd') = '#FFFFFFFF'             
$psISE.Options.TokenColors.item('GroupStart') = '#FFFFFFFF'             
$psISE.Options.TokenColors.item('LineContinuation') = '#FFFFFFFF'             
$psISE.Options.TokenColors.item('NewLine') = '#FFFFFFFF'             
$psISE.Options.TokenColors.item('StatementSeparator') = '#FFFFFFFF'             
$psISE.Options.TokenColors.item('Comment') = '#FFAEAEAE'             
$psISE.Options.TokenColors.item('String') = '#A2BC13'             
$psISE.Options.TokenColors.item('Keyword') = '#FFFFDE00'             
$psISE.Options.TokenColors.item('Attribute') = '#FF84A7C1'             
$psISE.Options.TokenColors.item('Type') = '#FF84A7C1'             
$psISE.Options.TokenColors.item('Variable') = '#EE9A00'             
$psISE.Options.TokenColors.item('CommandParameter') = '#FFFFDE00'             
$psISE.Options.TokenColors.item('CommandArgument') = '#FFFFFFFF'             
$psISE.Options.TokenColors.item('Number') = '#FF4169E1'             
$psISE.Options.TokenColors.item('LoopLabel') = '#FF4169E1'

Importing xml themes

While you could create a bunch of scripts to change your themes on command, a much better way is to use xml theme files. By using xml theme files, you can take advantage of the color adjustment features of the Options panel. You can also export your changes for use elsewhere. 

When I read about themes and played around with the color options, I was excited to see all the various PowerShell theme collections people must have created by now. Unfortunately, I couldn't find any theme collections out there. I couldn't even find many themes let alone theme collections. So I took the few themes I did find and put them together and attached them here.  

To use them do the following:
  1. Download and extract the theme files.
  2. Open the ISE and select Tools > Options.
  3. Select Manage Themes and import the extracted theme files.

Potential to script the import method

Although Microsoft did a nice job incorporating the theme option, they came up a little short in that you cannot import a theme using a PowerShell command. Kind of funny considering the nature of the product being themed.

Fortunately it won't take much to work around this deficiency. With a simple look through the registry, I can see they are creating string values with the content of the xmls stored as the data. It won't take much to create a function to do that! From there, I can build it into a form with preview pictures. Perhaps I can find some time to write this but I digress for now...

UPDATE: This has been done! Now you can import, change themes, and modify themes from the command line. Check out my latest post and grab my new ISE Theme Cmdlets! 

Themes contained in zip file

Here are some screenshots of the themes contained in the zip file. The original theme sources are also contained in the zip file.





My favorite of these 4 is Monokai. If you have an ISE color theme you'd like to share, let me know and I'll add it to this collection and update this post.

Here's the theme zip: