gpt4 book ai didi

powershell - 将Write-Host语句重定向到文件

转载 作者:行者123 更新时间:2023-12-03 13:41:32 24 4
gpt4 key购买 nike

我有一个正在调试的PowerShell脚本,想将所有Write-Host语句重定向到一个文件。有一个简单的方法吗?

最佳答案

Until PowerShell 4.0, Write-Host sends the objects to the host. It does not return any objects.

Beginning with PowerShell 5.0 and newer, Write-Host is a wrapper for Write-Information, which allows to output to the information stream and redirect it with 6>> file_name.


http://technet.microsoft.com/en-us/library/hh849877.aspx
但是,如果您有很多 Write-Host语句,请将它们全部替换为 Write-Log,它使您可以决定是输出到控制台,文件还是事件日志,还是全部输出到这三个。
另请检查:
  • Add-Content
  • redirection operators>, >>, 2>, 2>, 2>&1
  • Write-Log
  • Tee-Object
  • Start-Transcript
  • 关于powershell - 将Write-Host语句重定向到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5588689/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com