Powershell send-mailmessage失败

时间:2016-02-26 00:29:13

标签: powershell

我从cmd .bat脚本运行此PowerShell命令。它似乎在抱怨'请求'作为一个论点。命令中唯一的“请求”在引号内。发生了什么事?

M:>powershell send-mailmessage -to "pwatson@company.com" -from "pwatson@company.com" -subject "Standard Extract Request" -SmtpServer "mail.company.com" -attachment "file.txt"

Send-MailMessage : A positional parameter cannot be found that accepts argument 'Request'.
At line:1 char:1
+ send-mailmessage -to pwatson@company.com -from pwatson@company.com -subject Stan ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SendMailMessage

1 个答案:

答案 0 :(得分:2)

如果要从CMD运行PowerShell语句,则必须用双引号将整个语句括起来。尽可能在该字符串中使用单引号。

powershell.exe -Command "Send-MailMessage -To 'pwatson@company.com' -From 'pwatson@company.com' -Subject 'Standard Extract Request' -SmtpServer 'mail.company.com' -Attachment 'file.txt'"
相关问题