I have powershell script which sends text message through a sms-gateway. I get the message content from a txt file without any returns but I always receive text messages with the content and the last characters 0D 0A. How can I avoid this characters?
This is my powershell code:
$path = "C:\test.txt"
$EmailAddress = "test@test.com"
$smtpServer = "123.456.789.10"
$smsGateway = "0123456789@smsgateway.com"
$subject = "asdawadWA5556WAAA"
$body = get-content $path
[string]$stringBody = $body |out-string
send-mailmessage -From $EmailAddress -To $smsGateway -Subject $subject -Body $stringBody -Smtpserver $smtpServer
Since PowerShell strings are really .NET strings, you can use the handy
String.Trimmethod to remove leading and trailing whitespace characters; theses include0x0Dand0x0A, the ASCII carriage return and line feed characters that make up a standard Windows newline phrase.All you have to do is add the
.Trim()call to the argument to theBodyparameter: