Need help with getting output from a Powershell monitor that measures email RTT. We are having issues in our environment with the pre-built email RTT monitors in SAM, so I wrote this out of necessity.
The script get's accurate information back, but whenever I test the script I get the error Get Output Failed. The Output is there, I just am bumping my head against a wall figuring out what is wrong with the output.
Here is the script:
$From = "email1@domain.com"
$To = "email2@domain.org"
$Subject = "Email Round Trip Time Test"
$Body = "This email is a test to measure the round trip time."
$SMTPServer = "smtp.domain.com"
$SMTPUsername = "email1@domain.com"
$SMTPPassword = "password"
$SMTPClient = New-Object System.Net.Mail.SmtpClient($SMTPServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($SMTPUsername, $SMTPPassword)
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
$StartTime = Get-Date
try {
$SMTPClient.Send($From, $To, $Subject, $Body)
$EndTime = Get-Date
$RoundTripTime = ($EndTime - $StartTime).TotalMilliseconds
return $RoundTripTime
}
catch {
return -1
}
It returns this output with this example of an error
Get Output Failed: Output: ==============================================
1843.7587
Screenshot of error:

I am sure that it is something simple I am missing, but what would be recommended to get the output from the script?