链式异常的 Powershell 详细输出

标签 powershell powershell-2.0 cmdlets cmdlet

我是 powershell 的新手,我对我们的自定义 cmdlet 之一的问题进行了故障排除。默认情况下,cmdlet 中抛出的所有异常都具有最少的信息,没有堆栈跟踪,也没有关于链式异常的信息。有没有办法启用异常的详细输出?

最佳答案

这是我从网上某人那里偷来的一个巧妙的功能:)。我在我的个人资料中有它,并且很乐意进一步传播它:

#Get detailed information on an error
function Resolve-Error ($ErrorRecord=$Error[0])
{
   $ErrorRecord | Format-List * -Force
   $ErrorRecord.InvocationInfo |Format-List *
   $Exception = $ErrorRecord.Exception
   for ($i = 0; $Exception; $i++, ($Exception = $Exception.InnerException))
   {   "$i" * 80
       $Exception |Format-List * -Force
   }
}

关于链式异常的 Powershell 详细输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5944071/

相关文章:

powershell - New-UnifiedGroup 不适用于 ErrorAction

powershell - 是否有等效于 [System.IO.Path]::GetFullPath($fileName); 的 powershell cmdlet?当 $fileName 不存在时?

html - 使用 powershell 单击网页上的链接,然后传递凭据

powershell - 是否可以将 $profile 的默认值更改为新值?

powershell - Powershell 中所有进程的 CPU 和内存使用率百分比

Powershell 字符串长度验证

Powershell 和 TFS : tf. exe 与 Power tools TFS cmdlet?

windows - 将小的 PS 脚本转换为 .BATch 文件中的长行

powershell - Azure Powershell 选择带有订阅 ID 的 AzureSubscription

Azure (PowerShell) 如何向多个现有网络安全组添加额外的 IP(源地址前缀字段)?