Write-Host => Export to a file

前端 未结 4 1601
孤街浪徒
孤街浪徒 2021-01-08 00:34

I have got a script with some commands such as Write-Host \"Server1\". How can I export it to a file?

When I tried with script > export.txt

4条回答
  •  迷失自我
    2021-01-08 00:58

    Write-Host redirects the output only to the console.

    You can use Write-Output and redirect to a file (> export.txt or pipe to Out-File export.txt)

    In the extreme case when you absolutely need to redirect all output from a script, take a look to this cmdlet:

    Start-Transcript
    Get-Help Start-Transcript -full
    

提交回复
热议问题