Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In PowerShell how to capture error, warning, write-host output into a single file?

In PowerShell how to capture error, warning, write-host output into a single file?

When I execute the external command/ write-warning/ write-error/ write-host I need all the information to be captured in a file.

when I redirect the write-error to a log file it will not show the same content as it's been displayed on the console. It will have some other information which I don't need.

Is it possible to prefix error with ERROR: , warning with WARN: in the log file?

like image 987
Harsha Avatar asked Mar 11 '10 12:03

Harsha


2 Answers

Have a look at PowerShell 2.0: A Configurable and Flexible Script Logger Module by Oisin. It should be possible to prefix the message with your custom string ('ERROR', 'WARN',...)

like image 106
stej Avatar answered Oct 20 '22 00:10

stej


The simple way to do this is to use cmd.exe e.g.:

cmd /c powershell.exe -file <path_to_script> > script.log
like image 3
Keith Hill Avatar answered Oct 19 '22 22:10

Keith Hill