PoshCode Archive  Artifact [ada08c3d2e]

Artifact ada08c3d2e29feca632202dc6c32aa5c00da2f15369e7e269c2d79b9a6cb376e:

  • File Resolve-Error.ps1 — part of check-in [9c9d278d68] at 2018-06-10 13:07:05 on branch trunk — From Windows PowerShell Cookbook (O’Reilly) by Lee Holmes (user: Lee Holmes size: 1552)

# encoding: ascii
# api: powershell
# title: Resolve-Error.ps1
# description: From Windows PowerShell Cookbook (O’Reilly) by Lee Holmes
# version: 0.1
# type: script
# author: Lee Holmes
# license: CC0
# x-poshcode-id: 2206
# x-archived: 2017-05-13T16:20:50
# x-published: 2011-09-09T21:42:00
#
#
#############################################################################
##
## Resolve-Error
##
## From Windows PowerShell Cookbook (O'Reilly)
## by Lee Holmes (http://www.leeholmes.com/guide)
##
##############################################################################

<#

.SYNOPSIS

Displays detailed information about an error and its context

#>

param(
    ## The error to resolve
    $ErrorRecord = ($error[0])
)

Set-StrictMode -Off

""
"If this is an error in a script you wrote, use the Set-PsBreakpoint cmdlet"
"to diagnose it."
""

'Error details ($error[0] | Format-List * -Force)'
"-"*80
$errorRecord | Format-List * -Force

'Information about the command that caused this error ' +
    '($error[0].InvocationInfo | Format-List *)'
"-"*80
$errorRecord.InvocationInfo | Format-List *

'Information about the error''s target ' +
    '($error[0].TargetObject | Format-List *)'
"-"*80
$errorRecord.TargetObject | Format-List *

'Exception details ($error[0].Exception | Format-List * -Force)'
"-"*80

$exception = $errorRecord.Exception

for ($i = 0; $exception; $i++, ($exception = $exception.InnerException))
{
    "$i" * 80
    $exception | Format-List * -Force
}