How to convert colored output of a console application (like MSBuild or PowerShell) into HTML format preserving colors?

colors, console-application, html, msbuild, powershell

Solution

Powershell team blogged this script, which captures console screen buffer up to the current cursor position and returns it in HTML format.

Problem

When I run certain console applications (particularly, MSBuild or PowerShell) they produce an output containing text of different colors (for warnings, errors etc). Sometimes I need to save it for a future analysis, or to send it in an e-mail. I only can copy plain text from the console, or redirect the program output to a file, but this way all colors are lost. Is there a way to capture an output of a console application in a color-preserving format like HTML or RTF?

Original source