Question:I am working on changing
Send-MailMessageformatting based on error or success. When there is an error, I would like to have the
Bodytext appear in red color. On success, I would like to change the
Subjectand email body text to Blue color. I was able to change the success email body to Blue color but the Subject and error email body does not work as expected.
Answer:You don’t need to create a new object if you’re just interested in interpolating the Inner Exception
Messageyou can simply use the Subexpression operator
$ErrorMessagewould become the following in HTML:
As aside, using the
.ToString()Method is definitely not recommended in this case, if the error you’re catching does not have an Inner Exception, you would get a new error.
You cannot call a method on a null-valued expression.
If you have better answer, please add a comment about this, thank you!