【发布时间】:2016-04-13 01:42:12
【问题描述】:
ErrorDetails.RecommendedAction 属性如何以及何时使用?默认情况下似乎不会使用它:
using namespace System
using namespace System.Management.Automation
$exception = New-Object Exception -ArgumentList "This is the Exception message"
$errorRecord = New-Object ErrorRecord -ArgumentList $exception, "This is the ErrorRecord Message", NotSpecified, $null
$errorDetails = New-Object ErrorDetails -ArgumentList "This is the ErrorDetails message"
$errorRecord.ErrorDetails = $errorDetails
$errorDetails.RecommendedAction = "This is the recommended action"
Write-Error $errorRecord
: This is the ErrorDetails message
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
【问题讨论】:
-
Powershell
Get-Help 'about_Try_Catch_Finally' -ShowWindow -
PS 以自定义格式显示某些类型。有关详细信息,请参阅
help about_format.ps1xml。在 ErrorRecord 的情况下,默认不显示 RecommendAction。您可以这样做:$errorRecord|select *或$errorRecord|ft *查看所有 ErrorRecord 字段。或$errorRecord.recommendedaction只访问一个字段。 -
差不多,但不完全正确 - 它位于
$ErrorRecord.ErrorDetails.RecommendedAction
标签: powershell error-reporting