gpt4 book ai didi

powershell - 如何在执行期间将 PowerShell 的输出重定向到文件

转载 作者:行者123 更新时间:2023-12-03 01:25:56 24 4
gpt4 key购买 nike

我有一个 PowerShell 脚本,我想将其输出重定向到文件。问题是我无法更改该脚本的调用方式。所以我不能这样做:

 .\MyScript.ps1 > output.txt

如何在执行期间重定向 PowerShell 脚本的输出?

最佳答案

也许Start-Transcript适合您。如果它已经在运行,则首先停止它,然后启动它,完成后停止它。

$ErrorActionPreference="SilentlyContinue"Stop-Transcript | out-null$ErrorActionPreference = "Continue"Start-Transcript -path C:\output.txt -append# Do some stuffStop-Transcript

You can also have this running while working on stuff and have it saving your command line sessions for later reference.

If you want to completely suppress the error when attempting to stop a transcript that is not transcribing, you could do this:

$ErrorActionPreference="SilentlyContinue"
Stop-Transcript | out-null
$ErrorActionPreference = "Continue" # or "Stop"

关于powershell - 如何在执行期间将 PowerShell 的输出重定向到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1215260/

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