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!
Simple answer is to use a Tee-Object. In version 3 you should have access to the -Append parameter as well (but not in v2)
Write-Output "Error: whatever message" | Tee-Object -Append $Log_file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With