简体   繁体   中英

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?

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',...)

执行此操作的简单方法是使用cmd.exe,例如:

cmd /c powershell.exe -file <path_to_script> > script.log

Perhaps Start-Transcript and Stop-Transcript will do what you want. (PowerShell 2.0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM