«

»

Mar 08 2012

Want to add color to PowerShell code in your docs?

I was writing a Word document and wanted syntax highlighting for my PowerShell scripts.  It turns out that ISE (Integrated Scripting Environment) has an extension for copying text with color (and for copying text with color as HTML).  Just do the following:

  1. Install the PowerShellPack.msi file from here.
  2. Open ISE and your .ps1 PowerShell file.
  3. In the bottom third of the window, enter the following PowerShell command:
    1. Import-Module PowerShellPack
  4. You will now see an Add-ons menu in ISE; it may have already been there.
  5. Highlight the PowerShell code you wish to copy and choose Add-ons, IsePack, Edit, Copy-Colored from the menu.
  6. Now switch to Word and paste in your PowerShell code with full syntax highlighting.
  7. You can also use Copy-ColoredAsHtml to put syntax-highlighted HTML into your clipboard.
  8. Note that Ctrl-Shift-C will perform the Copy-Colored function and Ctrl-Alt-Shift-C will perform the Copy-ColoredAsHtml function.

This information came from “How to Insert Formatted Windows PowerShell Code on TechNet Wiki (en-US)“.