2016-02-26 120 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