只是为了表明,@JamesKo,如果你问错了问题,你就会得到错误的答案:-(。有几个人在这里基于 (a) 缺乏 Linux 接触和 (b) 你对这个术语的使用提出了善意的答案verbose。接下来,我将向您介绍 Linux 与 PowerShell 在这个主题上的关系,但如果您赶时间,请随时跳到最后的答案。 :-)
背景
在 PowerShell 中,verbose 具有非常具体的含义PowerShell 手册页甚至相当模糊:
显示有关执行的操作的详细信息
命令。此信息类似于跟踪或跟踪中的信息
交易日志。该参数仅在命令生成时起作用
一条详细的消息。
它甚至听起来像是你想要的......但是让我们将其与 Linux 文档进行比较set -x
根据您对 Linux 的喜好,可能是这样的(来自手册页项目)...
shell 应在之后将每个命令的跟踪写入标准错误
它会在执行命令之前扩展命令。
或这个(来自gnu)...
打印简单命令的痕迹,对于命令,case命令,选择
命令,以及命令及其参数的算术或
关联词列表在展开之后和之前
被执行。
你问题的第一行清楚而简洁地与这些一致。但 PowerShell 中的 verbose 是不同的。简而言之,打开详细模式(无论是-Verbose
命令行开关或$VerbosePreference
变量)只是启用从详细流到控制台的输出。 (就像 Linux 提供两个流,stdout 和 stderr 一样,PowerShell 提供多个流:输出流、错误流、警告流、详细流和调试流。您可以以与 Linux 相同的方式使用这些流 - 您可以甚至使用,例如commands 4>&1
例如,将详细流合并到标准输出。 (您可以在《基本写作流》部分中阅读有关 PowerShell 的多个输出流的更多信息PowerShell 一行:访问、处理和写入数据一个很好的快速参考是PowerShell 标点符号完整指南.)
答案
The 设置 PSDebug命令将为您提供与 bash 等效的跟踪。您甚至可以使用-Trace
范围。首先,这是控件,在使用之前Set-PSDebug
:
PS> Get-PSDepth
0
值为1您会在执行时获得每一行代码,例如:
PS> Set-PSDebug -Trace 1
PS> Get-PSDepth
DEBUG: 1+ >>>> Get-PSDepth
DEBUG: 141+ >>>> {
DEBUG: 142+ >>>> $nest = -1
DEBUG: 143+ >>>> $thisId = $pid
DEBUG: 144+ while ( >>>> (ps -id $thisId).Name -eq 'powershell') {
DEBUG: 145+ >>>> $thisId = (gwmi win32_process -Filter "processid='$thisId'").ParentProcessId
DEBUG: 146+ >>>> $nest++
DEBUG: 144+ while ( >>>> (ps -id $thisId).Name -eq 'powershell') {
DEBUG: 148+ >>>> $nest
0
DEBUG: 149+ >>>> }
值为2您还可以获得变量分配和代码路径:
PS> Set-PSDebug -Trace 2
PS> Get-PSDepth
DEBUG: 1+ >>>> Get-PSDepth
DEBUG: ! CALL function '<ScriptBlock>'
DEBUG: 141+ >>>> {
DEBUG: ! CALL function 'Get-PSDepth' (defined in file 'C:\Users\msorens\Documents\WindowsPowerShell\profile.ps1')
DEBUG: 142+ >>>> $nest = -1
DEBUG: ! SET $nest = '-1'.
DEBUG: 143+ >>>> $thisId = $pid
DEBUG: ! SET $thisId = '9872'.
DEBUG: 144+ while ( >>>> (ps -id $thisId).Name -eq 'powershell') {
DEBUG: 145+ >>>> $thisId = (gwmi win32_process -Filter "processid='$thisId'").ParentProcessId
DEBUG: ! SET $thisId = '10548'.
DEBUG: 146+ >>>> $nest++
DEBUG: ! SET $nest = '0'.
DEBUG: 144+ while ( >>>> (ps -id $thisId).Name -eq 'powershell') {
DEBUG: 148+ >>>> $nest
0
DEBUG: 149+ >>>> }
这些是我编写的一个名为的简单 cmdlet 的痕迹Get-PSDepth
。它使用以下命令打印命令、分配等DEBUG
前缀,与实际输出混合在一起,在本例中是仅包含的单行0
.