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!
Posted on January 2, 2013, in Development and tagged powershell, Scripting, Syntax Highlighting. Bookmark the permalink. Leave a Comment.
Leave a Comment
Comments (0)