locked
Everything I want to log has to be in brackets RRS feed

  • Question

  • Does anyone know why i have to enclose everything I want to log in brackets?

    Below is an example.  It will display the information I want on the screen but not log it.  If I enclose it in brackets it does log it. I must be missing something.  Going though a script and enclosing ever line I want to log in brackets not only is time consuming but often throws a wrench in whatever I am working with.

    Write-Host We are looking for the $myservice service on the below servers:    | Tee-Object -FilePath $env:Temp\log.log -Append
    
    Write-Host $servers  | Tee-Object -FilePath $env:Temp\log.log -Append 
    

    The below will work fine but nothing I have read states this should be required.

    Thanks in advance

    {Write-Host We are looking for the $myservice service on the below servers: }   | Tee-Object -FilePath $env:Temp\log.log -Append
    
    {Write-Host $servers } | Tee-Object -FilePath $env:Temp\log.log -Append 
    
    


    R White

    Friday, October 24, 2014 1:42 PM

Answers

  • Write-Host does not output to the pipeline.  It only outputs to the console.  To send to a file you need to use direct output.

    'this is my message' | Tee-Object -FilePath$env:Temp\log.log -Append


    ¯\_(ツ)_/¯

    • Marked as answer by tnetplus Friday, October 24, 2014 2:08 PM
    Friday, October 24, 2014 2:01 PM

All replies