Reputation: 16226
I am running this PowerShell command from a cmd .bat script. It appears to be complaining about 'Request' as an argument. The only 'Request' in the command is inside quotes. What's going on?
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
Upvotes: 1
Views: 5462
Reputation: 200193
If you want to run PowerShell statements from CMD you must enclose the entire statement in double quotes. Use single quotes inside that string wherever possible.
powershell.exe -Command "Send-MailMessage -To '[email protected]' -From '[email protected]' -Subject 'Standard Extract Request' -SmtpServer 'mail.company.com' -Attachment 'file.txt'"
Upvotes: 2