Sky Line
Sky Line

Reputation: 47

How to redirect powershell.exe OUPUT and ERROR to two separate files?

I need to redirect the STDERR and STDOUT to two separate files.

I tried the following:

My question is how can I redirect STDERR and STDOUT to two separate files by running powershell.exe just once?

Upvotes: 2

Views: 4979

Answers (1)

Frode F.
Frode F.

Reputation: 54971

You can specify multiple redirections. Ex.

powershell.exe -file Sample.ps1 2>errors.txt 1>output.txt

Sample.ps1

Write-Error "This is a critial error"
Write-Output "This is output"
"This is also output"

Errors.txt

C:\Users\frode\Desktop\Sample.ps1 : This is a critial error
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Untitled202.ps1

Output.txt

This is output
This is also output

Upvotes: 3

Related Questions