代码之家  ›  专栏  ›  技术社区  ›  Nelson Rothermel

PowerShell“回声开启”

  •  18
  • Nelson Rothermel  · 技术社区  · 15 年前

    这是的副本 https://serverfault.com/questions/102098/powershell-script-showing-commands-run . 我觉得在这里问这个问题更合适。

    我在玩PowerShell脚本,它们工作得很好。然而,我想知道是否有任何方法也可以显示所有运行的命令,就像您自己手工输入它们一样。这类似于批处理文件中的“echo on”。我查看了PowerShell命令行参数Cmdlet,但没有发现任何明显的地方。

    4 回复  |  直到 7 年前
        1
  •  6
  •   Keith Hill    15 年前

    Start脚本不捕获任何exe输出。对我来说,这是一个阻碍表演的因素。我不想这么说,但我发现最好的方法是:

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

    这捕捉到了一切。

        2
  •  3
  •   Richard Berg    15 年前
    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:如果您需要记录本机控制台应用程序, you'll need a slight workaround

        3
  •  3
  •   wisbucky Ishan    7 年前
    Set-PSDebug -Trace 1
    
    • 0:关闭脚本跟踪。
    • 1:在脚本行运行时跟踪它们。
    • 2:跟踪脚本行,变量 分配、函数调用和脚本。

    更多信息: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-psdebug?view=powershell-6

        4
  •  2
  •   Roman O    11 年前

    我在所需命令中添加了-verbose。例如。

    Copy-Item c:\xxx d:\xxx -verbose
    
    推荐文章