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:
I couldn't get both errors and results in the same file. A workaround that worked for me:
.\MyScript.ps1 2> C:\errors.txt | tee -filePath C:\results.txt
Update: I have worked further and I used Start-Transcript and Stop-Transcript in my mode to capture everything and it worked!
Start-Transcript
Stop-Transcript