Forum Discussion
tryllzhuud
Mar 19, 2024Copper Contributor
Output in CLI different that what is saved in log file ?!
Hi, I have the below command which shows errors, both in the Shell, and also logs into a log file. Function errMessage { param([Parameter(Mandatory=$true)][String]$err) Write-Warning -Message $(...
LainRobertson
Mar 19, 2024Silver Contributor
Hi, Touqueer.
Superficially, it looks like an encoding issue with the file, as that's what a Unicode stream output to an ANSI file tends to appear like.
Separately, Tee-Object is not technically positioned correctly.
The idea behind Tee-Object is that it splits one input channel into two destinations: a file and then the standard pipeline. Pipeline redirection is not required in this scenario.
With that in mind, simply:
- Construct the string;
- Pipe it to Tee-Object first;
- Let Tee-Object work as intended, where it sends the input to a file as well as the standard output;
- Leave Write-Warning last, which takes the standard pipeline input and writes it to the warning pipeline.
Example
"Boo!" | Tee-Object -FilePath "D:\Data\Temp\Forum\warning.log" | Write-Warning;
Output (screen)
Output (file)
Cheers,
Lain
tryllzhuud
Mar 19, 2024Copper Contributor