I have a set of powershell scripts that are invoked from the command line. Currently, the script returns a success or failure code.
Sometimes some powershell commands in scripts cause an error. I want to capture all the output (logs / message / error). I found that I can use a command like
. \ test.ps1 2> & 1 | foreach-object {$ _. ToString ()} | Out-File e: \ log.txt
Although this protocol logs an error message, the following problems
It simply logs the error message, not the line number that appears when I run the same script from the powershell console.
Now there is no output from the command line. I do not want to hide the output from the console and I want the entry in PowerShell to be optional.
I need to change the script invocation command. Is there any separate tool that can trigger and capture the output coming from the powershell window.
source
share