Avoiding newline in write-output

前端 未结 4 936
故里飘歌
故里飘歌 2020-12-03 17:23

I want to collect all output from my script in a log file and must use write-output instaed of write-host.

Write-Output \"Server:\" $a looks like

4条回答
  •  隐瞒了意图╮
    2020-12-03 17:38

    Write-Output "Server: $a"
    Write-Output ("Server: {0}" -f $a)
    Write-Output ("Server: " + $a)
    

    If you want to collect the output from a script into a log file, consider using Start-Transcript. It logs every command and all PowerShell output to a file. It doesn't log anything sent to stdout, however, so if you're using any legacy commands, you'll have to pipe their output to Write-Host:

    Start-Transcript C:\logs\mylog.txt
    Write-Host "Server: " $a
    ping | Write-Host
    

提交回复
热议问题