Reputation: 3302
I have set of powershell scripts which gets invoke from command prompt. Currently script returns the success or failure code.
Sometime some of the powershell commands in the scripts throws error. I want to capture all the output (logs/message/error). I found that I can use the command like
.\test.ps1 2>&1 | foreach-object {$_.ToString()} | Out-File e:\log.txt
Although this approch logs the error message however following are the problems
It just logs the error message not the line number which comes when I run the same script from the powershell console.
Now there is no output message from powershell. I do not want to hide the output from console & want powershell logging as additional thing.
I have to modify the script invocation command. Is there any standlone tool which can run & capture the output coming on the powershell window.
Upvotes: 3
Views: 1966
Reputation: 1168
I was going to mention Start-Transcript as a great way to do it.
You can also make use of Get-History to find out what commands you entered.
Upvotes: 2
Reputation: 3302
Just found Start-Transcript and Stop-Transcript commands. We can use it to capture all the output content (error/message/info etc) to file.
Upvotes: 2