0

The following line of my code simply does not write to file the Out-File command:

Move-Item $item.Path $CaminhoCompleto -Force -WhatIf -Verbose |
    Out-File -Filepath $SaidaTXT -Append -NoClobber

On the screen it shows correctly, but the file is empty.

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
Glicério
  • 75
  • 1
  • 8

1 Answers1

3

-WhatIf messages are written directly to the console and can't be piped or redirected without running the statement in a different PowerShell process. You can capture the output with Start-Transcript, though.

Start-Transcript -Path $SaidaTXT -Append
Move-Item ...
Stop-Transcript
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328