Roman
Roman

Reputation: 4611

PowerShell: send console output to file without deafening this console output

I have a lot of PowerShell script. One main, that calls other, child ones. Those PS scripts in their turn call windows CMD scripts, bash scripts and console applications. All these scripts and applications write messages to console. PowerShell scripts, for example, are using Write-Host scriptlet for this purpose.

Question: how can I easely redirect (send) all this console output to some file, while not deafening (canceling) this console output? I want to be able to see whats going on from console output and also have history of messages in log file.

Thanks.

Upvotes: 13

Views: 15637

Answers (4)

Roman
Roman

Reputation: 4611

I've found script for grabbing console output: http://gallery.technet.microsoft.com/scriptcenter/e8fbffde-7d95-42d9-81de-5eb3d9c089e0. Script returns HTML to preserve colors.

The only big downside - you must call it at the end of your script to capture all console output it have made.

Upvotes: 2

Keith Hill
Keith Hill

Reputation: 201672

You can try Start-Transcript and Stop-Transcript. It has a couple of limitations like not capturing native exe output. It is also global to PowerShell session.

Upvotes: 5

Mike Shepard
Mike Shepard

Reputation: 18166

You'd probably need to write a custom host to do this. It's not a terribly hard thing to do, but it's does require some managed code.

Upvotes: 1

Diadistis
Diadistis

Reputation: 12174

You can use the tee equivalent of PowerShell : Tee-Object

PS: serverfault.com and/or superuser.com are more suitable for a question like this.

Upvotes: 6

Related Questions