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:
- Install the PowerShellPack.msi file from here.
- Open ISE and your .ps1 PowerShell file.
- In the bottom third of the window, enter the following PowerShell command:
- Import-Module PowerShellPack
- You will now see an Add-ons menu in ISE; it may have already been there.
- Highlight the PowerShell code you wish to copy and choose Add-ons, IsePack, Edit, Copy-Colored from the menu.
- Now switch to Word and paste in your PowerShell code with full syntax highlighting.
- You can also use Copy-ColoredAsHtml to put syntax-highlighted HTML into your clipboard.
- 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)“.