0

I'm trying to run Send-MailMessage directly from a command window.

C:\>powershell Send-MailMessage -from '[email protected]' -to "[email protected]" -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.

1 Answer 1

2

If you're running this from cmd.exe then you need to check out the PowerShell.exe help:

C:\> poweshell.exe /?

Specifically you should invoke the command like so:

C:\> powershell -command "& {Send-MailMessage -from '[email protected]' ... }"

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.

Sign up to request clarification or add additional context in comments.

1 Comment

do you know how to make the command multiline ? to be executed from bat ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.