I have a lot of PowerShell script. One main, that calls other, child ones. Those PS scripts in their turn call windows CMD scripts, bash scripts and console applications. All these scripts and applications write messages to console. PowerShell scripts, for example, are using Write-Host
scriptlet for this purpose.
我有很多PowerShell脚本。一个主要的,称为其他的,儿童的。那些PS脚本轮流调用windows CMD脚本,bash脚本和控制台应用程序。所有这些脚本和应用程序都将消息写入控制台例如,PowerShell脚本正在使用Write-Host scriptlet来实现此目的。
Question: how can I easely redirect (send) all this console output to some file, while not deafening (canceling) this console output? I want to be able to see whats going on from console output and also have history of messages in log file.
问题:如何轻松地将所有此控制台输出重定向(发送)到某个文件,而不是震耳欲聋(取消)此控制台输出?我希望能够看到从控制台输出发生的事情,还有日志文件中的消息历史记录。
Thanks.
谢谢。
4 个解决方案
#1
5
You can try Start-Transcript
and Stop-Transcript
. It has a couple of limitations like not capturing native exe output. It is also global to PowerShell session.
您可以尝试Start-Transcript和Stop-Transcript。它有一些限制,如不捕获本机exe输出。 PowerShell会话也是全球性的。
#2
6
You can use the tee
equivalent of PowerShell : Tee-Object
您可以使用相当于PowerShell:Tee-Object的T恤
PS: serverfault.com and/or superuser.com are more suitable for a question like this.
PS:serverfault.com和/或superuser.com更适合这样的问题。
#3
2
I've found script for grabbing console output: http://gallery.technet.microsoft.com/scriptcenter/e8fbffde-7d95-42d9-81de-5eb3d9c089e0. Script returns HTML to preserve colors.
我找到了用于获取控制台输出的脚本:http://gallery.technet.microsoft.com/scriptcenter/e8fbffde-7d95-42d9-81de-5eb3d9c089e0。脚本返回HTML以保留颜色。
The only big downside - you must call it at the end of your script to capture all console output it have made.
唯一的大缺点 - 您必须在脚本结束时调用它来捕获它所做的所有控制台输出。
#4
1
You'd probably need to write a custom host to do this. It's not a terribly hard thing to do, but it's does require some managed code.
您可能需要编写自定义主机才能执行此操作。这不是一件非常困难的事情,但确实需要一些托管代码。
#1
5
You can try Start-Transcript
and Stop-Transcript
. It has a couple of limitations like not capturing native exe output. It is also global to PowerShell session.
您可以尝试Start-Transcript和Stop-Transcript。它有一些限制,如不捕获本机exe输出。 PowerShell会话也是全球性的。
#2
6
You can use the tee
equivalent of PowerShell : Tee-Object
您可以使用相当于PowerShell:Tee-Object的T恤
PS: serverfault.com and/or superuser.com are more suitable for a question like this.
PS:serverfault.com和/或superuser.com更适合这样的问题。
#3
2
I've found script for grabbing console output: http://gallery.technet.microsoft.com/scriptcenter/e8fbffde-7d95-42d9-81de-5eb3d9c089e0. Script returns HTML to preserve colors.
我找到了用于获取控制台输出的脚本:http://gallery.technet.microsoft.com/scriptcenter/e8fbffde-7d95-42d9-81de-5eb3d9c089e0。脚本返回HTML以保留颜色。
The only big downside - you must call it at the end of your script to capture all console output it have made.
唯一的大缺点 - 您必须在脚本结束时调用它来捕获它所做的所有控制台输出。
#4
1
You'd probably need to write a custom host to do this. It's not a terribly hard thing to do, but it's does require some managed code.
您可能需要编写自定义主机才能执行此操作。这不是一件非常困难的事情,但确实需要一些托管代码。