问题描述
这是 https://serverfault.com/questions/102098/powershell- 的副本脚本显示命令运行.我觉得在这里问这个问题比较合适.
This is a duplicate of https://serverfault.com/questions/102098/powershell-script-showing-commands-run. I thought it would be more appropriate to ask this question here.
我正在使用 PowerShell 脚本,它们运行良好.但是,我想知道是否有任何方法可以显示所有已运行的命令,就像您自己手动输入它们一样.这类似于批处理文件中的回显".我查看了 PowerShell 命令行参数和 cmdlet,但没有发现任何明显的东西.
I am playing around with PowerShell scripts and they're working great. However, I am wondering if there is any way to also show all the commands that were run, just as if you were manually typing them in yourself. This would be similar to "echo on" in batch files. I looked at the PowerShell command-line arguments, the cmdlets, but I didn't find anything obvious.
推荐答案
Start-Transcript 没有捕获任何 exe 输出.这对我来说是一个表演终结者.我不想这么说,但我发现这样做的最好方法是:
Start-Transcript doesn't catch any exe output. That's a show stopper for me. I hate to say it but the best way I've found to do this is:
cmd /c powershell.exe -file c:usershillrfoo.ps1 > foo.log
这捕获了所有 AFAICT.
This captures everything AFAICT.
这篇关于PowerShell“回显"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!