drifter213
drifter213

Reputation: 109

Out-File doesn't write any output

I have the following problem:

The script doesn't write anything in my export.txt file, but it does say "File found!"...

$client = "my-workstation"
$file = "c$\Windows\System32\notepad.exe"
$export = "C:\temp\export.txt"

If(Test-Path "\\$client\$file")
{
   write-host $client | Out-File $export
   write-host "File found!"
}

Upvotes: 1

Views: 566

Answers (1)

Martin Brandl
Martin Brandl

Reputation: 58931

The Write-Host cmdlet writes messages to the console, it doesn't put anything to the pipeline thus you have to omit the Write-Host:

$client | Out-File $export

Upvotes: 2

Related Questions