I always to wanted to make my powershell codes look beautiful in my blog but I didn’t find any tool which can help me in this regard. I used Syntax Highlighter for some days but my blog readers expressed concerns in using the code that I generated using Syntax Highlighter . So I removed it completely and ran my blog with just black and white code for some days.
I am a follower of RaviKanth chagati blog and I liked the way he colorizes his powershell code in posts. I approached him for help and he is kind enough to offer. Surprisingly, the solution is within powershell region and I no need to use any external tools to add color to my code.
I thought of making a post about this so that other bloggers who post about powershell like me can also benefit from this.
So, let us go ahead and see how we can add color to powershell code.
Launch your “Powershell Integrated Scripting Environment” Console which we use for writing powershell code. You quickly launch it by running “powershell_ise” from RUN command.
Once opened, import ISEPACK powershell module and execute the code in ISE by pressing “F5”. Now you will notice “Add-ons” tab in Powershell_ise.
Now paste your working code(or write directly in powershell_ise editor) in editor and press “Ctrl+Alt+Shift+C”(it does nothing but triggering copy-coloredHTML function in isepack module) and this will generate HTML equivalent of the code you have written in powershell ISE and make the HTML code available in clipboard. You can post paste operation anywhere to see the HTML code.
If you like GUI mode, you can do the code generation by triggering copy-coloredHTML function like shown below.
Once the code is available, let us move to content manger ( I use “wordpress”). In HTML portion of new post form, paste the HTML code that you generated and switch to Visual tab to view the preview.
I did above yesterday for 3 posts and output is very nice. You can view them below.
https://techibee.com/powershell/powershell-change-monitor-brightness/1022
https://techibee.com/sysadmins/powershell-minimize-all-windows/1017
https://techibee.com/scripting/powershell-get-cpu-architecture-on-windows-7-computer/1012