To redirect the output of a PowerShell to a file during its execution


Most often I need to capture the output of a script that I am executing to a text file. This is very useful when the command does not support output to a file.

$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue"
Start-Transcript -path C:\screen-output.txt -append
# DO YOUR EXECUTION COMMAND HERE
Stop-Transcript