Question:
I’m new to powershell and troubleshooting an issue with one of our custom cmdlets. By default, all exceptions thrown within the cmdlet have minimum information, no stack trace and no info on chained exceptions. Is there a way to enable verbose output of exceptions?
Answer:
Here’s a neat function that I’ve stolen from someone on the ‘net :). I have it in my profile and will happily spread it further:
1 2 3 4 5 6 7 8 9 10 11 12 |
#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 } } |