tags:

views:

23

answers:

1

Hi,

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.

A: 

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]' ... }"

What 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.

Keith Hill