Write-Host "Errors" -BackgroundColor Red
$Error.Clear()
{Some 1200 lines code}
I want to create a table after code excution with two columns: "Error" and "Line", if there were any errors in code above. But I failed using PSCustomObject (PSObject). It doesn't create table.
[PSCustomObject] @{
Error = $_.Exception.Message
Line = $_.InvocationInfo.ScriptLineNumber
}
New-Object PSObject -Property @{
Error = $Error.Exception.Message
Line = $Error.InvocationInfo.ScriptLineNumber
}
Due to too many line in code I do not want to use tey/catch, so how to combine output from? Or even is it possible without using try/catch?..
$Error.Exception.Message
$Error.InvocationInfo.ScriptLineNumber