PowerShell“回显”
这是 https://serverfault.com/questions/102098/powershell-script-showing 的重复项-命令运行。我觉得这个问题在这里问比较合适。
我正在尝试使用 PowerShell 脚本,它们运行得很好。但是,我想知道是否有任何方法可以显示所有运行的命令,就像您自己手动输入它们一样。这类似于批处理文件中的“回显”。我查看了 PowerShell 命令行参数、cmdlet,但没有发现任何明显的东西。
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.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
分配、函数调用和脚本。
有关详细信息:https ://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-psdebug?view=powershell-6
assignments, function calls, and scripts.
For more info: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-psdebug?view=powershell-6
Start-Transcript 不捕获任何 exe 输出。这对我来说是一个阻碍。我不想这么说,但我发现做到这一点的最好方法是:
这捕获了 AFAICT 的所有内容。
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:
This captures everything AFAICT.
我将 -verbose 添加到所需的命令中。例如
I added -verbose to desired commands. E.g.
注意#1:它只记录写入主控制台输出流的内容,而不记录警告/错误/调试。
注意#2:如果您需要录制本机控制台应用程序,你需要一个小小的解决方法
Note #1: it only records things written to the main console output stream, not Warning / Error / Debug.
Note #2: if you need to record native console applications, you'll need a slight workaround