PowerShell Syntax Highlighting script

As a SharePoint administrator, I end up either writing a lot of PowerShell scripts or copying existing scripts and modifying them to fit a new need.  With all of these scripts comes the need to share them with other admins outside of the command line and in such a way that allows them to be easily read.  To this end, I thought that something that could do syntax highlighting would really be handy so I set out in search of some way to parse a PowerShell script, highlight it and then create a self-contained HTML file that could then be used elsewhere or even just pasted into SharePoint in some fashion.

After some searching, I ran across Helge Klein’s script that does exactly what I was looking for – well, almost.  His script perfectly parsed a PowerShell file and created an HTML file with the highlighting but was limited in that it could only apply color to the various elements in the output.  I needed to also specify bolding and italics so I updated his script to use CSS classes instead of fixed colors. This gives almost unlimited flexibility to formatting including background colors, images, custom fonts, or whatever else your CSS mind can come up with.

I hope someone else finds it useful!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s