I am trying to write the entire output (errors included) of an executing script to the console and a file at the same time. I have tried several different options:
.\MyScript.ps1 | tee -filePath C:\results.txt # only the output to the file
.\MyScript.ps1 2> C:\results.txt # only the errors to the file and not the console
.\MyScript.ps1 > C:\results.txt # only the output to the file and not the console
My hope was that I could use the file to review the output/errors.
EDIT:
This is my current test script. The desired results is that all three messages can be seen.
function Test-Error
{
echo "echo"
Write-Warning "warning"
Write-Error "error"
}
Test-Error 2>&1 | tee -filePath c:\results.txt
Have you tried:
2>&1is what you’re looking forNote: This answer works great in PowerShell 1.0 and 2.0, but will capture ONLY standard output and errors in PowerShell 3.0 and later.