Brtrnd
Brtrnd

Reputation: 196

Powershell: Out-File

I'm trying to log all console output to a file. move-item D:\scripts\fileA D:\scripts\fileB -verbose -Force | Out-File D:\scripts\move.log -Append

the file is being created if it doesn't exist. But the verbose information and eventual powershell errors are not present in this file. How can I get this info?

Upvotes: 3

Views: 1746

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

The pipe only captures the success output stream, not the error and verbose streams. To capture the latter as well you need to redirect it to the former:

Move-Item "D:\scripts\fileA" "D:\scripts\fileB" -Verbose -Force 2>&1 4>&1 |
  Out-File D:\scripts\move.log -Append

See Get-Help about_Redirection for more information.

Upvotes: 5

Related Questions