During the creation of a PowerShell SMA Runbook I was getting the following error message. This error appear when sending an automatic mail message with the send-mailmessage cmdlet. It only happens when the subject is filled with a String parameter which contains invalid characters.
After two hours of troubleshooting I formatted the string with the following regex which worked in my case:
1 2 |
$subject = $string -Replace "[^ -~]", "" Send-MailMessage -Subject $subject -Body $body -from $from -SmtpServer $server -to $to |