I have a lot of PowerShell script. One main, that calls other, child ones. Those PS scripts in their turn call windows CMD scripts, bash scripts and console applications. All these scripts and applications write messages to console. PowerShell scripts, for example, are using Write-Host
scriptlet for this purpose.
Question: how can I easely redirect (send) all this console output to some file, while not deafening (canceling) this console output? I want to be able to see whats going on from console output and also have history of messages in log file.
Thanks.
The Out-Printer cmdlet sends output to the default printer or to an alternate printer, if one is specified. This cmdlet was reintroduced in PowerShell 7. This cmdlet is only available on Windows systems that support the Windows Desktop.
You can also use PowerShell to write to file by appending to an existing text file with Add-Content Cmdlet. To append “This will be appended beneath the second line” to our existing file, first-file. txt, enter this command and press enter.
You can use the tee
equivalent of PowerShell : Tee-Object
PS: serverfault.com and/or superuser.com are more suitable for a question like this.
You can try Start-Transcript
and Stop-Transcript
. It has a couple of limitations like not capturing native exe output. It is also global to PowerShell session.
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