I'm trying to execute the following command via command line
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe Send-MailMessage -from "mail.me" -to "mail.me" -Subject "PS test !" -Body "Hi this is a power shell mail test" -SmtpServer "mail.domain.com"
But I'm getting the following error :
Send-MailMessage : A positional parameter cannot be found that accepts arguement « test ».
Au niveau de ligne : 1 Caractère : 17
+ Send-MailMessage <<<< -from mail.me -to mail.me -Subject PS test ! -Body Hi this is a power shell mail test -SmtpServer mail.domain.com
+ CategoryInfo : InvalidArgument: (:) [Send-MailMessage], Paramet
erBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell
.Commands.SendMailMessage
The problem is that the same command works well when directly executed in Power Shell, but without the path.
What could be the problem generating this exception ?
Use -command
and braces. Currently, you are launching powershell and passing it multiple arguments instead of asking it to execute your code.
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command "& {Send-MailMessage -from "mail.me" -to "mail.me" -Subject "PS test !" -Body "Hi this is a power shell mail test" -SmtpServer "mail.domain.com"}"
I'm getting errors for the some of values you have set (characters that need to be escaped, invalid emails etc), so replaced and got this to run:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& {Send-MailMessage -From [email protected] -To [email protected] -Subject "whatevs" -SmtpServer "localhost" -Body "whatevs"}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With