-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathFormat-Error.ps1
More file actions
32 lines (31 loc) · 1.11 KB
/
Format-Error.ps1
File metadata and controls
32 lines (31 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
function Format-Error {
<#
.SYNOPSIS
Format $error[x] output.
.DESCRIPTION
Unknown source.
.PARAMETER ErrorRecord
The error entry to format.
.EXAMPLE
#resolve the latest error record ($error[0])
Resolve-Error
#>
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline,
Position = 0)]
$ErrorRecord = $Error[0]
)
PROCESS {
$error_message = "`nErrorRecord:{0}ErrorRecord.InvocationInfo:{1}Exception:{2}"
$formatted_errorRecord = $ErrorRecord | Format-List * -force | Out-String
$formatted_invocationInfo = $ErrorRecord.InvocationInfo | Format-List * -force | Out-String
$formatted_exception = ""
$Exception = $ErrorRecord.Exception
for ($i = 0; $Exception; $i++, ($Exception = $Exception.InnerException)) {
$formatted_exception += $Exception | Format-List * -force | Out-String
$formatted_exception += "`n"
}
return $error_message -f $formatted_errorRecord, $formatted_invocationInfo, $formatted_exception
}
}