简体   繁体   中英

Send-MailMessage parameter from command prompt

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:

C:\> poweshell.exe /?

Specifically you should invoke the command like so:

C:\> powershell -command "& {Send-MailMessage -from 'test@test.com' ... }"

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM