3

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?

Brtrnd
  • 196
  • 15

1 Answers1

5

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.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • Just to add to what Ansgar stated, this is the way both *nix and Windows systems handle output; an output stream and an error stream. Error streams are outputted immediately, in an attempt to output as much data as possible in case a crash is imminent (it is diagnostic after all, allowing one to collect logs or whatever and triage the issue); whereas the standard output stream is not so responsive. So if you want both, you have to tell it to send file descriptor 2 (stderr) to the same place as file descriptor 1 (stdout). FD 3, btw, is stdin. – ash Jun 13 '13 at 15:30
  • There are a few more streams as well, e.g. warnings and verbose messages. Those are redirectable from within PowerShell but won't show up as separate streams to the outside world. – Joey Jun 14 '13 at 18:20
  • 1
    @ash Stdin is FD 0. File descriptors 3-9 are for additional files/output streams in [Unix shells](http://www.tldp.org/LDP/abs/html/io-redirection.html) as well as in [CMD](http://technet.microsoft.com/en-us/library/bb490982.aspx). In PowerShell stream 3 is for redirecting warnings, 4 is for verbose and 5 for debug output. – Ansgar Wiechers Jun 14 '13 at 19:22
  • @AnsgarWiechers oops, I meant FD 0 for stdin, thanks for catching that. Also, thanks for the other FDs, I wasnt aware of some of those. – ash Jun 14 '13 at 21:51