PowerShell“回显”

发布于 2024-08-17 11:06:00 字数 334 浏览 10 评论 0原文

这是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

走野 2024-08-24 11:06:00
Set-PSDebug -Trace 1
  • 0:关闭脚本跟踪。
  • 1:跟踪运行时的脚本行。
  • 2:跟踪脚本行,变量
    分配、函数调用和脚本。

有关详细信息:https ://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-psdebug?view=powershell-6

Set-PSDebug -Trace 1
  • 0: Turn script tracing off.
  • 1: Trace script lines as they run.
  • 2: Trace script lines, variable
    assignments, function calls, and scripts.

For more info: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-psdebug?view=powershell-6

温柔少女心 2024-08-24 11:06:00

Start-Transcript 不捕获任何 exe 输出。这对我来说是一个阻碍。我不想这么说,但我发现做到这一点的最好方法是:

cmd /c powershell.exe -file c:\users\hillr\foo.ps1 > foo.log

这捕获了 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:

cmd /c powershell.exe -file c:\users\hillr\foo.ps1 > foo.log

This captures everything AFAICT.

伴我老 2024-08-24 11:06:00

我将 -verbose 添加到所需的命令中。例如

Copy-Item c:\xxx d:\xxx -verbose

I added -verbose to desired commands. E.g.

Copy-Item c:\xxx d:\xxx -verbose
离旧人 2024-08-24 11:06:00
C:\workspaces\silverlight> start-transcript -?

NAME
    Start-Transcript
    
SYNOPSIS
    Creates a record of all or part of a Windows PowerShell session in a text file.
    
    
SYNTAX
    Start-Transcript [[-Path] <string>] [-Append] [-Force] [-NoClobber] [-Confirm] [-WhatIf] [<CommonParameters>]
    
    
DESCRIPTION
    The Start-Transcript cmdlet creates a record of all or part of a Windows PowerShell session in a text file. The transcript includes all command that the user
     types and all output that appears on the console.
    

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113408
    Stop-Transcript 

REMARKS
    To see the examples, type: "get-help Start-Transcript -examples".
    For more information, type: "get-help Start-Transcript -detailed".
    For technical information, type: "get-help Start-Transcript -full".

注意#1:它只记录写入主控制台输出流的内容,而不记录警告/错误/调试。

注意#2:如果您需要录制本机控制台应用程序,你需要一个小小的解决方法

C:\workspaces\silverlight> start-transcript -?

NAME
    Start-Transcript
    
SYNOPSIS
    Creates a record of all or part of a Windows PowerShell session in a text file.
    
    
SYNTAX
    Start-Transcript [[-Path] <string>] [-Append] [-Force] [-NoClobber] [-Confirm] [-WhatIf] [<CommonParameters>]
    
    
DESCRIPTION
    The Start-Transcript cmdlet creates a record of all or part of a Windows PowerShell session in a text file. The transcript includes all command that the user
     types and all output that appears on the console.
    

RELATED LINKS
    Online version: http://go.microsoft.com/fwlink/?LinkID=113408
    Stop-Transcript 

REMARKS
    To see the examples, type: "get-help Start-Transcript -examples".
    For more information, type: "get-help Start-Transcript -detailed".
    For technical information, type: "get-help Start-Transcript -full".

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文