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? powershell powershell

In PowerShell how to capture error, warning, write-host output into a single 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',...)


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

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


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