PowerShell “echo on”

前端 未结 4 1912
忘掉有多难
忘掉有多难 2020-12-24 01:03

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.

相关标签:
4条回答
  • 2020-12-24 01:26
    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://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/set-psdebug?view=powershell-6

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-24 01:40

    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.

    0 讨论(0)
  • 2020-12-24 01:42

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

    Copy-Item c:\xxx d:\xxx -verbose
    
    0 讨论(0)
提交回复
热议问题