After reading Jason Slaughter's TechNet Blog post on Exchange ActiveSync logging via PowerShell, I realized that I wasn't satisfied with the default syntax highlighting in PowerShell, and went on a quest to find out how to improve it. As it turns out, I wasn't able to find much on the topic online. The PowerGUI wiki mentions that it's possible to change via an XML file, but doesn't go into much more detail than that. Adam at CSharpening.net has a blog post with the results of his foray into the topic, which also pointed me to the list of named colors that could be used, which came in handy.
Using this as a foundation, I got to work.
First, a couple of quick notes. In order to save your changes to the PowerShellSyntax,xml file, you're going to have to open it with elevated rights. Also, these changes don't take effect immediately, so you're going to have to close and re-open PowerGUI each time you make changes in order to see their effects.
As I worked through the different styles, I realized that I actually wasn't sure when some of them were supposed to be applied, so I wrote a syntax test script with examples of each type, and a block at the bottom that lists the strings that trip each type. You can snag it from GitHub.
One of the first things I noticed when working my way through the XML was that the AutoVars style was not used anywhere. There's a PSAutoVars group defined, but it uses the VariableStyle style. I changed that, since a separate highlighting style makes sense for these variables:
Find:
<ExplicitPatternGroup TokenKey="PSAutoVars" TokenID="23" Style="VariableStyle" LookAhead="{NonWordMacro}|\z" CaseSensitivity="AutoCorrect">
Replace with:
<ExplicitPatternGroup TokenKey="PSAutoVars" TokenID="23" Style="AutoVars" LookAhead="{NonWordMacro}|\z" CaseSensitivity="AutoCorrect">
In the list below that line, I also added $true and $false, since those are also built-in variables that I wanted highlighted using this style.
That done, I messed with styles themselves. Here's what I finally settled on:
<!-- Highlighting Styles --> <Styles> <Style Key="ReservedWordStyle" ForeColor="Blue" Italic="True" /> <Style Key="OperatorStyle" ForeColor="Red" /> <Style Key="OperatorWordStyle" ForeColor="Red" /> <Style Key="VariableStyle" ForeColor="DarkSlateGray" Bold="True" /> <Style Key="CmdletStyle" ForeColor="Blue" /> <Style Key="NetClassStaticStyle" ForeColor="teal" /> <Style Key="NetClassStaticMethodStyle" ForeColor="saddlebrown" /> <Style Key="CmdletParamStyle" ForeColor="Navy" /> <Style Key="NumberStyle" ForeColor="Black" /> <Style Key="StringDelimiterStyle" ForeColor="Purple" /> <Style Key="StringDefaultStyle" ForeColor="Purple" Italic="True" /> <Style Key="CommentDelimiterStyle" ForeColor="Green" /> <Style Key="CommentDefaultStyle" ForeColor="Green" /> <Style Key="AutoVars" ForeColor="DarkOrange" Bold="True"/> <Style Key="FunctionStyle" ForeColor="CadetBlue" /> </Styles>
And a side-by-side for ya:
