Today very simple trick to capture whole output from Powershell. Let’s see those files:

1.ps1

2.ps1

3.bat

4.vbs

5.exe

6.exe

Let’s now run this with powershell:

Okay, we have all STD OUT and STD ERR streams. Let’s now try redirecting this to file:

File content:

Okay, so standard output was redirected correctly but standard error and write-host was not. Let’s try this:

File content:

Okay, we have almost whole output in the file. Only write-host was not redirected. Can we do better?

The trick is to use CMD:

File content:

Now we have everything in file. How to see it in the console as well?

File output:

Now it works correctly.