2016-02-26 179 views
0

我从cmd .bat脚本运行此PowerShell命令。它似乎在抱怨'要求'作为一个论点。命令中的唯一'请求'在引号内。这是怎么回事?Powershell发送邮件失败

M:>powershell send-mailmessage -to "[email protected]" -from "[email protected]" -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 [email protected] -from [email protected] -subject Stan ... 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : InvalidArgument: (:) [Send-MailMessage], ParameterBindingException 
    + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SendMailMessage 
+0

你是从CMD运行的吗? – Kiran

回答

1

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

powershell.exe -Command "Send-MailMessage -To '[email protected]' -From '[email protected]' -Subject 'Standard Extract Request' -SmtpServer 'mail.company.com' -Attachment 'file.txt'" 
+0

我看到这个工程,但它工作之前。谢谢你的帮助。 – lit