59

これはhttps://serverfault.com/questions/102098/powershell-script-showing-commands-runの複製です。ここでこの質問をするのがより適切だと思いました。

私は PowerShell スクリプトをいじっていますが、うまく機能しています。ただし、実行されたすべてのコマンドを自分で手動で入力しているかのように表示する方法があるかどうか疑問に思っています。これは、バッチ ファイルの「エコー オン」に似ています。PowerShell のコマンド ライン引数、コマンドレットを調べましたが、明確なものは見つかりませんでした。

4

4 に答える 4

60
Set-PSDebug -Trace 1
  • 0: スクリプトのトレースをオフにします。
  • 1: 実行時にスクリプト行をトレースします。
  • 2: スクリプト行、変数割り当て、関数呼び出し、およびスクリプトをトレースします。

詳細情報: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-psdebug?view=powershell-6

于 2018-04-04T09:30:04.833 に答える
13

Start-Transcript は exe 出力をキャッチしません。それは私にとってショーストッパーです。言いたくないのですが、これを行うために私が見つけた最良の方法は次のとおりです。

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

これにより、AFAICT のすべてがキャプチャされます。

于 2010-01-14T15:16:09.283 に答える
4
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

于 2010-01-14T15:04:05.860 に答える