Powershell display message both on console and in a file

Viewed 5782

Not sure if this is a simple question or some code is required in order to achieve this, so here it goes.

I have a script which basically displays some text 1st on the PS console and also in a log file.

The code I have uses both the write-host and write-output, so my question is that if the 2 can be combined somehow? I want only specific message to be logged, so doing a PS transcript will not work.

Write-host "Error: whatever message" 
Write-Output "Error: whatever message" | Out-File -Append $Log_file

Thanks in advance!

2 Answers
Related