When an error occurs in a script I have been attempting to capture the error message from the Error object:
# this doesn't seem to work
$msg = $Error[0].Message
My understanding is the $Error is a collection of exceptions. I have tried various ways to access the object and also looked at the Format-List * output.
Can anyone suggest the best way to capture the error message from a Error[n] object?
Business Case: clear, concise error logging; do not desire the whole exception object.
@kvprasoon - good to know! (Thanks) We are targeting the lowest common denominator since this code has to work in a variety of environments. Seems there is still some Win 2012 running PS 4 in use. I would have hoped for at least PS 5.1. I am looking forward to the rest of the world catching up!