I'm working on a PowerShell script that sends an email every time and error is encountered. I am trying the convert the $error[0] arraylist into the string but it's giving me the message:
You cannot call a method on a null-valued expression.
Here's the chunk of code that I have in my catch block.
Catch [Exception]
{
$Message = New-Object System.Exception "Error: " + $error[0].Exception.InnerException.ToString()
Send-MailMessage -Port $port -smtpServer $smtpservername -to $to -from $from -subject $subject -body [string] $Message
throw ($Message)
}
Any ideas on how to achieve this?