Glicério
Glicério

Reputation: 75

PowerShell Out-File is not working

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.

Upvotes: 0

Views: 1939

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200293

-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

Upvotes: 3

Related Questions