Why the following command not have any efect?

William Torrez 0 Reputation points
2025-10-05T14:11:54.2+00:00

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]

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. _AW_ 63,226 Reputation points Volunteer Moderator
    2025-10-06T02:35:48.67+00:00

    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.

    1 person found this answer helpful.

  2. Viorel 124.9K Reputation points
    2025-10-05T14:36:11.1466667+00:00

    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
    

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.