Copy Color-Coded PowerShell to HTML

Copy Color-Coded PowerShell to HTML

Q: How can I copy Windows PowerShell code into a HTML page and keep the color highlighting of the text?

A: Often I create PowerShell code in the Windows 8 PowerShell Integrated Scripting Environment (ISE), which does a great job of color-coding the text to make it easy to understand the different elements. However, this gets lost as soon as it's pasted into HTML.

I found a great add-on for the ISE to enable the copying of PowerShell from the ISE into color-coded HTML. Perform the following:

  1. Download the PowerShell Pack from Microsoft.
  2. Install the downloaded MSI file.
  3. Launch the PowerShell ISE.
  4. Type the command below to import the PowerShell Pack module:
    Import-Module PowerShellPack
  5. On the ISE menu will be Add-ons, which will include a IsePack sub-menu.
  6. Select the code in the Scripting pane, then go to Select Add-ons,  IsePack, Edit, Copy-ColoredAsHtml (see screen shot below).
  7. In your HTML editor in the Source view, select Paste, which will have the color-formatted HTML as the example shows below:

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish