Writing errors and output to a text file and Console

前端 未结 4 1900
走了就别回头了
走了就别回头了 2021-02-02 08:48

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:



        
4条回答
  •  佛祖请我去吃肉
    2021-02-02 09:26

    Have you tried:

     .\MyScript.ps1 2>&1 | tee -filePath c:\results.txt
    

    2>&1 is what you're looking for

    Note: 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.

提交回复
热议问题