Powershell 如何使详细消息显示在Start Transcript的输出中?

Powershell 如何使详细消息显示在Start Transcript的输出中?,powershell,Powershell,使用Start Transcript时verbose输出不会被捕获到转录本中。例如: Start-Transcript Write-Verbose "This is a test of verbose output" Stop-Transcript 结果: ********************** Windows PowerShell transcript start Start time: 20170829110436 Username: xx\xx RunAs User: xx\xx

使用
Start Transcript时
verbose输出不会被捕获到转录本中。例如:

Start-Transcript
Write-Verbose "This is a test of verbose output"
Stop-Transcript
结果:

**********************
Windows PowerShell transcript start
Start time: 20170829110436
Username: xx\xx
RunAs User: xx\xx
Machine: SGC340 (Microsoft Windows NT 6.1.7601 Service Pack 1)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 19596
PSVersion: 5.0.10586.117
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0.10586.117
BuildVersion: 10.0.10586.117
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
Transcript started, output file is C:\Users\xx\Documents\PowerShell_transcript.xx.EbGyj9PE.20170829110436.txt
PS C:\Users\xx> Write-Verbose "This is a test of verbose output"
PS C:\Users\xx> Stop-Transcript
**********************
Windows PowerShell transcript end
End time: 20170829110447
**********************
如何在成绩单中捕获详细输出?

如本文所述,详细输出不会出现,因为
$VerbosePreference
的默认设置为
'SilentlyContinue'
。如果将其更改为“继续”,则会显示详细输出

同样,如果您的脚本使用了
Start Transcript
,则可以将
[cmdletbinding()]
添加到脚本的顶部,然后使用
-Verbose
开关执行脚本,以使详细消息在脚本中可见

请注意,运行
Start-Transcript-Verbose
不会启用记录成绩单中的详细消息(它只启用cmdlet本身的详细输出)