I’m trying to run Send-MailMessage directly from a command window.
C:\>powershell Send-MailMessage -from 'test@test.com' -to "target@test.com" -subject 'test' -smtpServer "srv.server.com" -Attachment c:\Test\log.txt -body "Test message"
This fails with
Send-MailMessage : A positional parameter cannot be found that accepts argument 'from'.
I’m sure it’s possible. I just dont know how to pass the arguments correctly.
If you’re running this from cmd.exe then you need to check out the PowerShell.exe help:
Specifically you should invoke the command like so:
Watch out for the quote characters. In general use double quotes around the whole -command parameter value for cmd.exe interpret. Inside the command use single quoted strings unless you need variable expansion inside the string.