Use Add-Content.
"This is a log message." | Add-Content "C:\Logs\HstOutput.log" -PassThru
Note: -PassThru so the log message is output to the console.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I try execute the following command from VSCODE:
# Outputs to the console
Write-Host "This is a log message." | Out-File -FilePath "C:\Logs\HostOutput.log" -Append
I don't get none result in the file.
The file is empty.
What happen?
I use VSCODE administrator mode.
[moved from Windows development › Windows API - Win32]
Use Add-Content.
"This is a log message." | Add-Content "C:\Logs\HstOutput.log" -PassThru
Note: -PassThru so the log message is output to the console.
Documentation says that Write-Host is to produce display-only output, and you can use these alternatives:
Write-Host "This is a log message." 6>> "C:\Logs\HostOutput.log"
or
Write-Output "This is a log message." | Out-File -FilePath "C:\Logs\HostOutput.log" -Append