English 中文(简体)
PowerShell "echo on"
原标题:

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.

最佳回答

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:usershillrfoo.ps1 > foo.log

This captures everything AFAICT.

问题回答
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

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

Copy-Item c:xxx d:xxx -verbose
C:workspacessilverlight> 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





相关问题
Eclipse: Hover broken in debug perspective

Since upgrading Eclipse (Galileo build 20090920-1017), hover in debug no longer displays a variable s value. Instead, hover behaves as if I were in normal Java perspective: alt text http://...

IIS 6.0 hangs when serving a web-service

I am having issues with one of our web-services. It works fine on my development machine (win XP) whether I host it as a separate application or using cassini from Visual studio. Once I deploy on the ...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Asp.Net MVC - Problem returning a model to the view

I ve recently started using the Areas functionality of the Preview2 and it was working ok until I needed to return a Model to the view. Controller: public ActionResult ForgotPassword() { return ...

Unable to generate PDB files in Visual Studio 2005

For most assemblies, I m able to generate their respective .pdb files. However, I ve got one project that isn t generating their .pdb files. I ve made sure that it on debug mode and that the project ...

热门标签