Sunday, June 08, 2014

Tip - Add Syntax highlighting for PowerShell Code

There are lot of ways to add syntax highlighting to the PowerShell code in your blog, see the post by MVP Francios Xavier-Cat.

I just happened to come across one more which is pretty easy to use and best part is it uses a PowerShell module to do so.

Follow the below steps :
  1. Download the Copy to Colorized HTML module and put the extracted copy in your Modules directory.
  2. Add the below code to your ISE Profile, which will add a submenu and the "Ctrl+Shift+C" shortcut to copy the HTML content in your clipboard. 

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add(“Copy As Colorized HTML”,{Copy-ColorizedHTML},“Ctrl+Shift+C”| Out-Null

The module has a single cmdlet called "Copy-ColorizedHTML" which copies the HTML content in your clipboard for use.

Once the content is copied to your clipboard just paste it to your blog.

NOTE - This method can also be used to while authoring an article for Technet Wiki.

see the animated GIF below:

Enjoy !


  1. Hi DexterPosh,

    I tried your module in ISE. The add-on is there but nothing is being copied to the clipboard. I'm using PowerShell version 5.0 currently. Any issues with that?



    1. Hi Irwin,

      Finally Tested this on an Azure VM with below PSversion and it works fine for me :


      Name Value
      ---- -----
      PSVersion 5.0.9841.0
      WSManStackVersion 3.0
      CLRVersion 4.0.30319.36323
      BuildVersion 6.4.9841.0
      PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
      PSRemotingProtocolVersion 2.2

  2. Hi Irwin,

    I haven't tested this on PowerShell v5. Let me try it.

    P.S. - This is not my module ;)


  3. Unfortunately the link for the module is dead! Can you re-post it please?

    1. Yeah the link is gone, I would suggest copy-pasting directly from VSCode now.