Quantcast
Channel: Rob V IT
Viewing all articles
Browse latest Browse all 64

PowerShell: The specified string is not in the form required for a subject

$
0
0

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:

$subject = $string -Replace "[^ -~]", ""
Send-MailMessage -Subject $subject -Body $body -from $from -SmtpServer $server -to $to

 

 

The post PowerShell: The specified string is not in the form required for a subject appeared first on Rob V IT.


Viewing all articles
Browse latest Browse all 64

Trending Articles