How to copy text from the cmd console and keep the formatting (with color)?

Solution 1:

The PowerShell folks, on their blog, posted an article titled: Colorized capture of console screen in HTML and RTF

Once it's in a RTF file, with colors, open the RTF with Word or OpenOffice and copy the text to your target application.

As PowerShell is a nice replacement of cmd.exe with a lot more features, give it a try.

Solution 2:

Snark's answer is useful, but the link is broken. The updated link to the MSDN blog post is here: Colorized capture of console screen in HTML and RTF

You need to copy the functions from the blog post and then paste them into PowerShell. And then you can run commands like:

$htmlFileName = "$env:temp\ConsoleBuffer.html"
.\Get-ConsoleAsHtml | out-file $htmlFileName -encoding UTF8